Sum digits of an integer: Difference between revisions
m
→{{header|Haskell}}
Line 2,011:
{{Out}}
<pre>30</pre>
In terms of unfoldr:
<lang haskell>import Data.List (unfoldr)
import Data.Tuple (swap)
----------------- SUM DIGITS OF AN INTEGER ---------------
baseDigitSum :: Int -> Int -> Int
baseDigitSum base
| otherwise
▲ then Just $ swap $ quotRem x base
-------------------------- TESTS -------------------------
main :: IO ()
main =
mapM_
print
[ baseDigitSum <$> [2, 8, 10, 16] <*> [255],
]</lang>
{{Out}}
|