Created
May 31, 2019 19:52
-
-
Save baudtack/22a6be0cc9d73696e105db4d09eeb828 to your computer and use it in GitHub Desktop.
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) | |
^$(i +(i)) | |
%= $ | |
j +(j) | |
mydeck [(num-to-suit i) j]^mydeck | |
== | |
++ 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.unshuffled shuffled] | |
=^ index random (rads:random remaining) | |
~! unshuffled | |
~! (snag index unshuffled) | |
%= $ | |
shuffled `deck`(snag index `deck`unshuffled)^`deck`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