Last active
August 29, 2015 14:03
-
-
Save bpicolo/7742aeb377e1cc22263b to your computer and use it in GitHub Desktop.
More like Badskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- I am probably overcomplicating basic haskell | |
-- toDigits <=0 = [] | |
-- toDigits 1230 = [1,2,3,0] | |
numDigits :: Integer -> Integer | |
numDigits n | |
| n <= 9 = 0 | |
| otherwise = 1 + numDigits (n `div` 10) | |
trueToDigits :: Integer -> [Integer] | |
trueToDigits n | |
| n < 10 = n : [] | |
| otherwise = n `div` (10 ^ numDigits n) : trueToDigits (n `mod` (10 ^ numDigits n)) | |
toDigits :: Integer -> [Integer] | |
toDigits n | |
| n <= 0 = [] | |
| otherwise = trueToDigits n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment