Skip to content

Instantly share code, notes, and snippets.

@baudtack
Created May 31, 2019 20:37
Show Gist options
  • Save baudtack/f182b8194c874845e5c5f66e26b47f3a to your computer and use it in GitHub Desktop.
Save baudtack/f182b8194c874845e5c5f66e26b47f3a to your computer and use it in GitHub Desktop.
!:
|%
+$ 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
=/ random ~(. og entropy)
=/ remaining (lent unshuffled)
|-
?~ unshuffled unshuffled
?~ t.unshuffled [i.unshuffled shuffled]
=^ index random (rads:random remaining)
%= $
shuffled (snag index `deck`unshuffled)^shuffled
remaining (dec remaining)
unshuffled (oust [index 1] `deck`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