list comprehensions!
This commit is contained in:
parent
7699137716
commit
82069dd346
@ -23,12 +23,8 @@ doubleEveryOther = revDigits . go []
|
|||||||
go acc [] = acc
|
go acc [] = acc
|
||||||
|
|
||||||
sumDigits :: [Integer] -> Integer
|
sumDigits :: [Integer] -> Integer
|
||||||
sumDigits = sumDigits' . flattenDigits . eachToDigits
|
sumDigits digits = foldDigits 0 (+) [y | x <- digits, y <- toDigits x]
|
||||||
where
|
where
|
||||||
eachToDigits = foldDigits [] (\n acc -> toDigits n : acc)
|
|
||||||
flattenDigits = foldDigits [] (++)
|
|
||||||
sumDigits' = foldDigits 0 (+)
|
|
||||||
|
|
||||||
foldDigits acc f (x : xs) = foldDigits (f x acc) f xs
|
foldDigits acc f (x : xs) = foldDigits (f x acc) f xs
|
||||||
foldDigits acc _ [] = acc
|
foldDigits acc _ [] = acc
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user