Narcissistic decimal number: Difference between revisions
Content added Content deleted
(→Haskell Reduced search (unordered digit combinations): simplified powerSum function) |
|||
Line 1,083: | Line 1,083: | ||
narcissiOfLength :: Int -> [Int] |
narcissiOfLength :: Int -> [Int] |
||
narcissiOfLength n = powerSum |
narcissiOfLength n = powerSum n <$> filter (isDaffodil n) (risingDigits n []) |
||
where |
where |
||
isDaffodil n ds = (sort . digitList . powerSum |
isDaffodil n ds = (sort . digitList . powerSum n) ds == ds |
||
powerSum :: |
powerSum :: Int -> [Int] -> Int |
||
powerSum |
powerSum n = foldr ((+) . (^ n)) 0 |
||
powerSum a n (x:xs) = powerSum (a + x ^ n) n xs |
|||
risingDigits 0 ns = ns |
risingDigits 0 ns = ns |