Jump to content

Perfect shuffle: Difference between revisions

Add SETL
m (syntax highlighting fixup automation)
(Add SETL)
Line 2,689:
1024. 10.
10000. 300.</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program faro_shuffle;
loop for test in [8, 24, 52, 100, 1020, 1024, 10000] do
print(lpad(str test, 5) + " cards: " + lpad(str cycle [1..test], 4));
end loop;
 
op cycle(l);
start := l;
loop until l = start do
l := shuffle l;
n +:= 1;
end loop;
return n;
end op;
 
op shuffle(l);
return [l(mapindex(i,#l)) : i in [1..#l]];
end op;
 
proc mapindex(i, size);
return if odd i then i div 2+1 else (i+size) div 2 end;
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 8 cards: 3
24 cards: 11
52 cards: 8
100 cards: 30
1020 cards: 1018
1024 cards: 10
10000 cards: 300</pre>
 
=={{header|Sidef}}==
2,095

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.