Narcissistic decimal number: Difference between revisions
Content added Content deleted
(→Functional Python: Simplified predicate, extended domain of digitList to 0.) |
(→Haskell :: Reduced search: Simpler predicate, digitList domain extended to 0) |
||
Line 2,041: | Line 2,041: | ||
isDaffodil :: Int -> Int -> Bool |
isDaffodil :: Int -> Int -> Bool |
||
isDaffodil 1 0 = True |
|||
isDaffodil e n = |
isDaffodil e n = |
||
(((&&) . (e ==) . length) <*> (n ==) . powerSum e) (digitList n) |
(((&&) . (e ==) . length) <*> (n ==) . powerSum e) (digitList n) |
||
Line 2,049: | Line 2,048: | ||
digitList :: Int -> [Int] |
digitList :: Int -> [Int] |
||
digitList 0 = [] |
digitList 0 = [0] |
||
digitList n = |
digitList n = go n |
||
where |
|||
go 0 = [] |
|||
go x = rem x 10 : go (quot x 10) |
|||
-- TEST ---------------------------------------------------------------------- |
|||
main :: IO () |
main :: IO () |