Narcissistic decimal number: Difference between revisions
m
→Haskell :: Reduced search (unordered digit combinations): Pruned and adjusted imports
m (→optimized, 3-digit chunks: split a long comment line.) |
m (→Haskell :: Reduced search (unordered digit combinations): Pruned and adjusted imports) |
||
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
narcissiOfLength :: Int -> [Int]
Line 2,029 ⟶ 2,028:
where
powers = ((,) <*> (^ nDigits)) <$> [0 .. 9]
go n parents
| otherwise =
f
|
| otherwise
parents >>=
(\(d, pwrSum) -> second (pwrSum +) <$> take (succ d) powers)
▲ (null parents)))
isDaffodil :: Int -> Int -> Bool
Line 2,054 ⟶ 2,051:
go 0 = []
go x = rem x 10 : go (quot x 10)
-- TEST ----------------------------------------------------------------------▼
main :: IO ()
main =
|