Card shuffles: Difference between revisions
Content deleted Content added
Added Lua version |
|||
Line 472: | Line 472: | ||
say (^20).pick(*); |
say (^20).pick(*); |
||
</lang> |
</lang> |
||
=={{header|Phix}}== |
|||
<lang Phix>function riffle(sequence s) |
|||
sequence res = {} |
|||
integer l = length(s) |
|||
integer r = rand(l) |
|||
for i=1 to l do |
|||
if r+i<=l then |
|||
res &= s[r+i] |
|||
end if |
|||
if i<=r then |
|||
res &= s[i] |
|||
end if |
|||
end for |
|||
return res |
|||
end function |
|||
function overhand(sequence s) |
|||
sequence res = {} |
|||
integer l = length(s) |
|||
while length(s) do |
|||
integer r = rand(l*0.2) |
|||
if r>length(s) then |
|||
r = length(s) |
|||
end if |
|||
res = s[1..r]&res |
|||
s = s[r+1..$] |
|||
end while |
|||
return res |
|||
end function |
|||
-- to shorten the output, all 2..7 have been removed from the deck |
|||
constant DECKSIZE=52-24 |
|||
procedure show_deck(sequence s) |
|||
for i=1 to DECKSIZE do |
|||
integer c = s[i]-1 |
|||
-- puts(1,"23456789TJQKA"[remainder(c,13)+1]&"HCDS"[floor(c/13)+1]&" ") |
|||
puts(1,"89TJQKA"[remainder(c,7)+1]&"HCDS"[floor(c/7)+1]&" ") |
|||
end for |
|||
puts(1,"\n") |
|||
end procedure |
|||
show_deck(riffle(tagset(DECKSIZE))) |
|||
show_deck(overhand(tagset(DECKSIZE))) |
|||
show_deck(shuffle(tagset(DECKSIZE)))</lang> |
|||
{{out}} |
|||
<pre> |
|||
TC 8H JC 9H QC TH KC JH AC QH 8D KH 9D AH TD 8C JD 9C QD KD AD 8S 9S TS JS QS KS AS |
|||
KS AS JS QS TS AD 8S 9S 9D TD JD QD KD QC KC AC 8D AH 8C 9C TC JC JH QH KH TH 8H 9H |
|||
KH TH AH QH 8D JC QC 8C JH 8H 9D KS TD AS KD 8S TC AD TS AC 9C KC 9H QD JD JS 9S QS |
|||
</pre> |
|||
=={{header|Racket}}== |
=={{header|Racket}}== |