No, Im not sure.

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.

Recursion is and stays a difficult subject for  me so .

Roelof


erzy Karczmarczuk schreef op 6-2-2015 om 16:44:
Are you sure??

Jerzy Karczmarczuk
::::::::::::::::::::::::::::::::::

Le 06/02/2015 16:40, Roelof Wobben a écrit :
Dmitry Olshansky schreef op 6-2-2015 om 16:25:
toDigits :: Integer -> [Integer]
toDigits n
   | n < 0 = []
   | n < 10 = [n]
   | otherwise =  toDigits (n `div` 10) ++ [n `mod` 10]


Thanks that worked,

I have now to figure out why I see [0] on 0 and no zero when it reaches it end-point.

isDigits 0
n< 10 so [0]

IsDigits 1

n < 0 not true
n < 10 not true.
toDigits  1  ++ [0]

toDigits 1 + [0]

n< 0 not true
n < 10 true so [1] ++ [0]

[1] ++ [0] is [1.0] where the output is [1]

So somehow I do not understand fully how this works .

Roelof







_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe