function six( p, used, n ) pieces = [ 1, 2, 3, 4, 5, 6; 4, 5, 6, 1, 2, 3; 3, 4, 5, 1, 2, 6; 1, 2, 4, 5, 6, 3; 4, 6, 1, 2, 5, 3; 1, 5, 3, 4, 6, 2; 5, 2, 6, 1, 3, 4;]; % 找到一組解 if ( n == 8 ) p return; end for i = 1:7 if( used(i) == 1 ) continue; end r = pieces(i,:); used(i) = 1; for j = 1:6 % 第一片不旋轉 if ( n == 1 && j ~= 1 ) continue; end r = clshift(r); p(n,:) = r; if( check(p) ) six( p, used, n + 1); end end used(i) = 0; end end