28 lines
532 B
Text
28 lines
532 B
Text
function New=PerfectShuffle(Nitems,Nturns)
|
|
if modulo(Nitems,2)==0 then
|
|
X=1:Nitems;
|
|
for c=1:Nturns
|
|
X=matrix(X,Nitems/2,2)';
|
|
X=X(:);
|
|
end
|
|
New=X';
|
|
end
|
|
endfunction
|
|
|
|
Result=[];
|
|
Q=[8, 24, 52, 100, 1020, 1024, 10000];
|
|
for n=Q
|
|
Same=0;
|
|
T=0;
|
|
Compare=[];
|
|
while ~Same
|
|
T=T+1;
|
|
R=PerfectShuffle(n,T);
|
|
Compare = find(R-(1:n));
|
|
if Compare == [] then
|
|
Same = 1;
|
|
end
|
|
end
|
|
Result=[Result;T];
|
|
end
|
|
disp([Q', Result])
|