I have a given string: abcdpqrs, where output will be: badcqpsr.
My current code:
f :: [a] -> [a]
f (a:b:xs) = b:a:xs
f xs = xs
Evaluating f "abcdpqrs"
results in "bacdpqrs"
. How can this be used to get "badcqpsr"?
I have a given string: abcdpqrs, where output will be: badcqpsr.
My current code:
f :: [a] -> [a]
f (a:b:xs) = b:a:xs
f xs = xs
Evaluating f "abcdpqrs"
results in "bacdpqrs"
. How can this be used to get "badcqpsr"?
Try processing more than just the first two characters by recursing on the remainder of the list:
f :: [a] -> [a]
f (a:b:xs) = b:a:f xs
f xs = xs