In math, when I want to rearrange a list of length n, I'll act on the list with a permutation. For example:
(1 2) * (x, y, z) = (y, x, z) (1 n 2) * (v[1], v[2], ..., v[n]) = (v[n], v[1], ..., v[2]) perm * (v[1], v[2], ..., v[n]) = ( v[perm(1)], v[perm(2)], ..., v[perm(n)] ) How would I do this in Haskell?
perm :: {1,2...,N} -> {1,2...,N}a bijection and so on. A O(N^2) algorithm should be rather simple, but your input in(1 n 2)is a rotational one, not a bijection. So decide: what's your actual input?nis bigger than3,(1 n 2)is a bijection that maps1 |-> n,n |-> 2,2 |-> 1, and all other values to themselves.