标签: haskell permutation
我有一个给定的字符串:abcdpqrs,其中输出为:badcqpsr。
我目前的代码:
f :: [a] -> [a] f (a:b:xs) = b:a:xs f xs = xs
评估f "abcdpqrs"结果为"bacdpqrs"。如何用它来获得" badcqpsr"?
f "abcdpqrs"
"bacdpqrs"
答案 0 :(得分:2)
通过递归列表的其余部分,尝试处理的不仅仅是前两个字符:
f :: [a] -> [a] f (a:b:xs) = b:a:f xs f xs = xs