Narcissistic decimal number: Difference between revisions

m
m (→‎optimized, 3-digit chunks: split a long comment line.)
Line 2,022:
In this way we can find the 25th narcissistic number after '''length $ concatMap digitPowerSums [1 .. 7] == 19447''' tests – an improvement on the exhaustive trawl through '''9926315''' integers.
 
<lang haskell>import ControlData.ArrowBifunctor (second)
import Data.Bool (bool)
 
narcissiOfLength :: Int -> [Int]
Line 2,029 ⟶ 2,028:
where
powers = ((,) <*> (^ nDigits)) <$> [0 .. 9]
go n parents =
| 0 < n = go (pred n) (nullf parents)))
bool
| otherwise = (filter (isDaffodil nDigits . snd) parents)
(gowhere
f (pred n)parents
| (boolnull parents = powers
| otherwise (parents >>=
parents >>=
(\(d, pwrSum) -> (second (pwrSum +) <$> take (succ d) powers)))
(\(d, pwrSum) -> second (pwrSum +) <$> take (succ d) powers)
(null parents)))
(0 < n)
 
isDaffodil :: Int -> Int -> Bool
Line 2,054 ⟶ 2,051:
go 0 = []
go x = rem x 10 : go (quot x 10)
 
-- TEST ----------------------------------------------------------------------
 
-- TEST ------------------------------------------- TEST ---------------------------
main :: IO ()
main =
9,659

edits