Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,50 @@
/* REXX ***************************************************************
* 1) Build ordered Card deck
* 2) Create shuffled stack
* 3) Deal 5 cards to 4 players each
* 4) show what cards have been dealt and what's left on the stack
* 05.07.2012 Walter Pachl
**********************************************************************/
colors='S H C D'
ranks ='A 2 3 4 5 6 7 8 9 T J Q K'
i=0
cards=''
ss=''
Do c=1 To 4
Do r=1 To 13
i=i+1
card.i=word(colors,c)word(ranks,r)
cards=cards card.i
End
End
n=52 /* number of cards on deck */
Do si=1 To 51 /* pick 51 cards */
x=random(0,n-1)+1 /* take card x (in 1...n) */
s.si=card.x /* card on shuffled stack */
ss=ss s.si /* string of shuffled stack */
card.x=card.n /* replace card taken */
n=n-1 /* decrement nr of cards */
End
s.52=card.1 /* pick the last card left */
ss=ss s.52 /* add it to the string */
Say 'Ordered deck:'
Say ' 'subword(cards,1,26)
Say ' 'subword(cards,27,52)
Say 'Shuffled stack:'
Say ' 'subword(ss,1,26)
Say ' 'subword(ss,27,52)
si=52
deck.=''
Do ci=1 To 5 /* 5 cards each */
Do pli=1 To 4 /* 4 players */
deck.pli.ci=s.si /* take top of shuffled deck */
si=si-1 /* decrement number */
deck.pli=deck.pli deck.pli.ci /* pli's cards as string */
End
End
Do pli=1 To 4 /* show the 4 dealt ... */
Say pli':' deck.pli
End
Say 'Left on shuffled stack:'
Say ' 'subword(ss,1,26) /* and what's left on stack */
Say ' 'subword(ss,27,6)

View file

@ -0,0 +1,32 @@
/*REXX pgm shows a method to build/shuffle/deal 5 cards (using a 52─card deck)──►4 hands*/
box = build(); say ' box of cards:' box /*a brand new standard box of 52 cards.*/
deck= mix(); say 'shuffled deck:' deck /*obtain a randomly shuffled deck. */
call deal 5, 4 /* ◄───────────────── 5 cards, 4 hands.*/
say; say; say right('[north]' hand.1, 60)
say; say ' [west]' hand.4 right('[east]' hand.2, 60)
say; say right('[south]' hand.3, 60)
say; say; say; say 'remainder of deck: ' deck
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
build: _=; ranks= "A 2 3 4 5 6 7 8 9 10 J Q K" /*ranks. */
if 5=='f5'x then suits= "h d c s" /*EBCDIC? */
else suits= "♥ ♦ ♣ ♠" /*ASCII. */
do s=1 for words(suits); $= word(suits, s)
do r=1 for words(ranks); _= _ word(ranks, r)$ /*append a suit to rank*/
end /*r*/
end /*s*/; return _ /*jokers are not used. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
deal: parse arg #cards, hands; hand.= /*initially, nullify all hands. */
do #cards /*deal a hand to all the players. */
do player=1 for hands /*deal some cards to the players. */
hand.player= hand.player word(deck, 1) /*deal the top card to a player. */
deck= subword(deck, 2) /*diminish deck, elide one card. */
end /*player*/
end /*#cards*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
mix: @=; _=box; #cards= words(_) /*define three REXX variables. */
do mixer=1 for #cards /*shuffle all the cards in deck. */
?= random(1, #cards + 1 - mixer) /*each shuffle, random# decreases.*/
@= @ word(_, ?) /*shuffled deck, 1 card at a time.*/
_= delword(_, ?, 1) /*elide just─chosen card from deck*/
end /*mixer*/; return @