2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,23 +1,23 @@
|
|||
/*REXX program shuffles a deck of playing cards using the Knuth shuffle.*/
|
||||
rank='A 2 3 4 5 6 7 8 9 10 J Q K' /*pips of the playing cards. */
|
||||
suit='♣♠♦♥' /*suit " " " " */
|
||||
parse arg seed .; if seed\=='' then call random ,,seed /*repeatability?*/
|
||||
say '────────────────── getting a new deck out of the box ···'
|
||||
deck.1='highJoker' /*good decks have a color joker, */
|
||||
deck.2='lowJoker' /*··· and a black & white joker. */
|
||||
cards=2 /*now, two cards are in the deck.*/
|
||||
/*REXX program shuffles a deck of playing cards (with jokers) using the Knuth shuffle.*/
|
||||
rank= 'A 2 3 4 5 6 7 8 9 10 J Q K' /*pips of the various playing cards. */
|
||||
suit= '♣♠♦♥' /*suit " " " " " */
|
||||
parse arg seed . /*obtain optional argument from the CL.*/
|
||||
if datatype(seed,'W') then call random ,,seed /*maybe use for RANDOM repeatability.*/
|
||||
say '══════════════════ getting a new deck out of the box ···'
|
||||
@.1= 'highJoker' /*good decks have a color joker, and a */
|
||||
@.2= 'lowJoker' /* ··· black & white joker. */
|
||||
cards=2 /*now, there're 2 cards are in the deck*/
|
||||
do j =1 for length(suit)
|
||||
do k=1 for words(rank); cards=cards+1
|
||||
deck.cards=substr(suit,j,1)word(rank,k)
|
||||
do k=1 for words(rank); cards=cards + 1
|
||||
@.cards=substr(suit, j, 1)word(rank, k)
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
call showDeck
|
||||
say '────────────────── shuffling' cards "cards ···"
|
||||
do s=cards by -1 to 2; rand=random(1,s)
|
||||
parse value deck.rand deck.s with deck.s deck.rand
|
||||
/* [↑] swap two cards in the deck*/
|
||||
call show
|
||||
say; say '══════════════════ shuffling' cards "cards ···"
|
||||
do s=cards by -1 to 2; ?=random(1,s); parse value @.? @.s with @.s @.?
|
||||
/* [↑] swap two cards in the deck. */
|
||||
end /*s*/
|
||||
call showDeck
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SHOWDECK subroutine─────────────────*/
|
||||
showDeck: _=; do m=1 for cards; _=_ deck.m; end /*m*/; say _; say; return
|
||||
call show
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: _=; do m=1 for cards; _=_ @.m; end /*m*/; say _; return
|
||||
|
|
|
|||
|
|
@ -1,30 +1,27 @@
|
|||
/*REXX program shuffles a deck of playing cards using the Knuth shuffle.*/
|
||||
rank = 'ace deuce trey 4 5 6 7 8 9 10 jack queen king' /*use pip names.*/
|
||||
suit = 'club spade diamond heart' /* " suit " */
|
||||
say '────────────────── getting a new deck out of the box ···'
|
||||
deck.1 = ' color joker' /*good decks have a color joker, */
|
||||
deck.2 = ' b&w joker' /*··· and a black & white joker. */
|
||||
cards=2 /*now, two cards are in the deck.*/
|
||||
/*REXX program shuffles a deck of playing cards (with jokers) using the Knuth shuffle.*/
|
||||
rank = 'ace deuce trey 4 5 6 7 8 9 10 jack queen king' /*use pip names for cards*/
|
||||
suit = 'club spade diamond heart' /* " suit " " " */
|
||||
say '══════════════════ getting a new deck out of the box ···'
|
||||
@.1= ' color joker' /*good decks have a color joker, and a */
|
||||
@.2= ' b&w joker' /* ··· black & white joker. */
|
||||
cards=2 /*now, there're 2 cards are in the deck*/
|
||||
do j =1 for words(suit)
|
||||
do k=1 for words(rank); cards=cards+1 /*bump counter.*/
|
||||
deck.cards=right(word(suit,j),7) word(rank,k) /*assign.*/
|
||||
do k=1 for words(rank); cards=cards+1 /*bump the card counter. */
|
||||
@.cards=right(word(suit,j),7) word(rank,k) /*assign a card name. */
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
|
||||
call showDeck 'ace' /*inserts blank when ACE is found*/
|
||||
say '────────────────── shuffling' cards "cards ···"
|
||||
call show 'ace' /*inserts blank when an ACE is found.*/
|
||||
say; say '══════════════════ shuffling' cards "cards ···"
|
||||
|
||||
do s=cards by -1 to 2; rand=random(1,s) /*get random number for swap*/
|
||||
_=deck.rand; deck.rand=deck.s; deck.s=_ /*swap 2 cards in card deck.*/
|
||||
end /*s*/
|
||||
|
||||
call showDeck
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────SHOWDECK subroutine─────────────────*/
|
||||
showDeck: parse arg break; say /*get sep card, shows blank line*/
|
||||
do m=1 for cards /*traipse through the deck. */
|
||||
if pos(break,deck.m)\==0 then say /*a blank: easier to read cards.*/
|
||||
say 'card' right(m,2) '───►' deck.m /*display a particular card. */
|
||||
end /*m*/
|
||||
say /*show a trailing blank line. */
|
||||
do s=cards by -1 to 2; ?=random(1,s); _=@.?; @.?=@.s; @.s=_
|
||||
end /*s*/ /* [↑] swap two cards in the deck. */
|
||||
call show
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: parse arg break; say /*get separator card, show blank line. */
|
||||
do m=1 for cards /* [↓] traipse through the card deck. */
|
||||
if pos(break,@.m)\==0 then say /*show a blank to read cards easier. */
|
||||
say 'card' right(m, 2) '───►' @.m /*display a particular card from deck. */
|
||||
end /*m*/
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue