for (int x=1; x < (1 << n); x++) { FromPole = (x&x-1)%3; ToPole = ((x|x-1)+1)%3; moveDisk(FromPole,ToPole); }