Skip to content

Instantly share code, notes, and snippets.

@bpicolo
Last active August 29, 2015 14:03
Show Gist options
  • Save bpicolo/7742aeb377e1cc22263b to your computer and use it in GitHub Desktop.
Save bpicolo/7742aeb377e1cc22263b to your computer and use it in GitHub Desktop.
More like Badskell
-- 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