unperm := proc(av) local a, n, b, i, j; a := av; n := nops(a); b := NULL; for i to n do if a[i] <> i then for j from i + 1 to n do if a[j] = i then break; end if; end do; if n < j then error "geen perm"; end if; a[j] := a[i]; a[i] := i; b := b, [i, j]; end if; end do; [b]; end proc; unperm([1, 2, 3]); [] unperm([1, 3, 2]); [[2, 3]] unperm([4, 5, 2, 1, 3]); [[1, 4], [2, 3], [3, 5]]