How I can permute one symbol back. I have a given string: abcdpqrs
, where output will be: badcqpsr
.
My current code:
f s = foldr (\a ~(x,y) -> (a:y,x)) ([],[]) s
main :: IO ()
main = do
str <- getLine
print(f str)
Evaluating f "abcdpqrs"
results in
("acpr",
"bdqs")
How can this be used to get "badcqpsr"
?
Updated code:
rev (a : b : xs) = b : a : rev xs
rev xs = xs
main = do
n <- getLine
l <- getContents
putStr (rev l)
When input are 2 strings, abcdpqrs
and az
result is badcqpsra
and z
. Expected output is badcqpsr
and za
. How I can fix it?