list comprehensions!

This commit is contained in:
Logan McGrath 2021-08-13 16:41:59 -07:00
parent 7699137716
commit 82069dd346

View File

@ -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