交换扩展到两个以上的变量?
  我一直试图将xor-swap扩展到两个以上的变量,比如n变量。  但是我没有任何地方比3*(n-1) 。 
  对于两个整数变量x1和x2你可以像这样交换它们: 
swap(x1,x2) {
  x1 = x1 ^ x2;
  x2 = x1 ^ x2;
  x1 = x1 ^ x2;
}
  所以,假设你有x1 ... xn的值为v1 ... vn 。  显然你可以通过连续应用交换来“旋转”数值: 
swap(x1,x2);
swap(x2,x3);
swap(x3,x4);
...
swap(xm,xn); // with m = n-1
  你将以x1 = v2 , x2 = v3 ,..., xn = v1 。 
  其中花费n-1掉期,每次花费3 xors,给我们留下(n-1)*3 xors。 
是一种更快的算法,仅使用xor和赋值,并且没有额外的变量已知?
作为一个部分结果,我尝试了一个蛮力搜索N = 3,4,5,所有这些都与你的公式一致。
Python代码:
from collections import *
D=defaultdict(int) # Map from tuple of bitmasks to number of steps to get there
N=5
Q=deque()
Q.append( (tuple(1<<n for n in range(N)), 0) )
goal = (tuple(1<<( (n+1)%N ) for n in range(N)))
while Q:
    masks,ops = Q.popleft()
    if len(D)%10000==0:
        print len(D),len(Q),ops
    ops += 1
    # Choose two to swap
    for a in range(N):
        for b in range(N):
            if a==b:
                continue
            masks2 = list(masks)
            masks2[a] = masks2[a]^masks2[b]
            masks2 = tuple(masks2)
            if masks2 in D:
                continue
            D[masks2] = ops
            if masks2==goal:
                print 'found goal in ',ops
                raise ValueError
            Q.append( (masks2,ops) )
