
Jerzy Karczmarczuk schreef op 6-2-2015 om 16:57:
Le 06/02/2015 16:48, Roelof Wobben a écrit :
Im only sure that somehow I take the wrong turn somewhere because I cannot figure out why I do not get the right answer.
I think I have the value of n wrong. Did you read my answer entirely? Do so, find the red fat line
You take n=1, and you write: n<10 not True. You don't need to be a specialist on recursion, to see the error.
Jerzy
oke, Another try : toDigits :: Integer -> [Integer] toDigits n | n < 0 = [] | n < 10 = [n] | otherwise = toDigits (n `div` 10) ++ [n `mod` 10] isDigits 1 n < 0 not true. n < 10 true so [1] IsDigits 12 n < 0 not true n < 10 not true toDigits 1 + [2] toDigits 1 + [2] n < 0 not true n < 10 true [1] ++ [2] 1 ++2 = [1,2] I think I understand it finnaly. Roelof