Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Knuth-shuffle/REXX/knuth-shuffle-1.rexx
Normal file
23
Task/Knuth-shuffle/REXX/knuth-shuffle-1.rexx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*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
|
||||
@.cards=substr(suit, j, 1)word(rank, k)
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
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 show
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
show: _=; do m=1 for cards; _=_ @.m; end /*m*/; say _; return
|
||||
27
Task/Knuth-shuffle/REXX/knuth-shuffle-2.rexx
Normal file
27
Task/Knuth-shuffle/REXX/knuth-shuffle-2.rexx
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/*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 the card counter. */
|
||||
@.cards=right(word(suit,j),7) word(rank,k) /*assign a card name. */
|
||||
end /*k*/
|
||||
end /*j*/
|
||||
|
||||
call show 'ace' /*inserts blank when an ACE is found.*/
|
||||
say; say '══════════════════ shuffling' cards "cards ···"
|
||||
|
||||
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
|
||||
23
Task/Knuth-shuffle/REXX/knuth-shuffle-3.rexx
Normal file
23
Task/Knuth-shuffle/REXX/knuth-shuffle-3.rexx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* 05.01.2014 Walter Pachl
|
||||
* borrow one improvement from version 1
|
||||
* 06.01.2014 removed -"- (many tests cost more than few "swaps")
|
||||
*--------------------------------------------------------------------*/
|
||||
Call random ,,123456 /* seed for random */
|
||||
Do i=1 To 10; a.i=i; End; /* fill array */
|
||||
Call show 'In',10 /* show start */
|
||||
do i = 10 To 2 By -1 /* shuffle */
|
||||
j=random(i-1)+1;
|
||||
h=right(i,2) right(j,2)
|
||||
Parse Value a.i a.j With a.j a.i /* a.i <-> a.j */
|
||||
Call show h,i /* show intermediate states */
|
||||
end;
|
||||
Call show 'Out',10 /* show fomaö state */
|
||||
Exit
|
||||
|
||||
show: Procedure Expose a.
|
||||
Parse Arg txt,n
|
||||
ol=left(txt,6);
|
||||
Do k=1 To n; ol=ol right(a.k,2); End
|
||||
Say ol
|
||||
Return
|
||||
Loading…
Add table
Add a link
Reference in a new issue