Created
May 29, 2019 18:47
-
-
Save baudtack/2e9a8df3c94da0aeb65fdfc6cbb5a123 to your computer and use it in GitHub Desktop.
updated playing cards
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!: | |
|% | |
+$ suit ?(%hearts %spades %clubs %diamonds) | |
+$ darc [sut=suit val=@ud] | |
+$ deck (list darc) | |
++ make-deck | |
^- deck | |
=| mydeck=deck | |
=/ i 1 | |
|- | |
?: (gth i 4) | |
mydeck | |
=/ j 1 | |
|- | |
?: (lte j 13) | |
%= $ | |
j +(j) | |
mydeck [(num-to-suit i) j]^mydeck | |
== | |
^$(i +(i)) | |
++ num-to-suit | |
|= val=@ud | |
^- suit | |
?+ val !! | |
%1 %hearts | |
%2 %spades | |
%3 %clubs | |
%4 %diamonds | |
== | |
++ shuffle-deck | |
|= [unshuffled=deck entropy=@] | |
^- deck | |
=| shuffled=deck | |
?~ unshuffled unshuffled | |
=/ random ~(. og entropy) | |
=/ remaining (lent unshuffled) | |
|- | |
?~ t.unshuffled [i.unshufffled shuffled] | |
=^ index random (rads:random remaining) | |
%= $ | |
shuffled (snag index unshuffled)^shuffled | |
remaining (dec remaining) | |
unshuffled (oust [index +(index)] unshuffled) | |
== | |
++ draw | |
|= [n=@ud d=deck] | |
^- [hand=deck rest=deck] | |
:- (scag n d) | |
(slag n d) | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment