Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
swap 0 j (x:xs) = idxAt (j-1) xs : set x (j-1) xs
where
idxAt 0 (x:_) = x
idxAt j (_:xs) = idxAt (j-1) xs
set x 0 (_:ys) = x:ys
set x j (y:ys) = y:set x (j-1) ys
swap i j (x:xs) = x : swap (i-1) (j-1) xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment