You need to increase every second element, starting from the right one in the Haskell list, but keep the order of origin (for example, it reversedoes not apply). For example:
f [1, 2, 3] -- [1, 3, 3]
f [1, 2, 3, 4] -- [2, 2, 4, 4]
I tried something like the following:
fc ([]) = []
fc (x:[]) = [x]
fc (x:[y]) = [x+1,y]
fc( x:xs ) = fc [x] : ( fc xs ) -- this line is wrong
ps Obviously, I could change (but prefer to understand the original task) in the list twice and apply something like:
helper (x:y:tail) = [x, y+1] ++ tail
fc x = reverse (helper (reverse x) )
Dewfy source
share