Anonymous user
Set puzzle: Difference between revisions
→{{header|REXX}}: re-read the requirements, found a hand with 4 sets, then showed the dealt hand.
(→{{header|REXX}}: added the REXX language. -- ~~~~) |
(→{{header|REXX}}: re-read the requirements, found a hand with 4 sets, then showed the dealt hand.) |
||
Line 1,849:
<lang rexx>/*REXX program finds "sets" (solutions) for the SET puzzle (game). */
parse arg game seed . /*get optional # cards to deal. */
if game ==',' | game==''
if seed
call
call
call dealer game /*deal a number of cards. */▼
call findSets game%2 /*find sets from the dealt cards.*/▼
exit sets /*stick a fork in it, we're done.*/
/*──────────────────────────────────AGAME subroutine────────────────────*/
aGame: tell=arg(1); good=game%2 /*enable or disable the output. */
/* [↑] GOOD is the right # sets.*/
do seed=seed until good==sets /*generate deals until good# sets*/
call random ,,seed /*repeatability for last invoke. */
call genFeatures /*generate various card features.*/
call genDeck /*generate a deck (with 81 cards)*/
end /*until*/ /*when leaving, SETS is right num*/
return /*return to invoker of this sub. */
/*──────────────────────────────────DEALER subroutine───────────────────*/
dealer:
do cards=1 until cards==game /*keep dealing 'til done*/
_=random(1,words(##)); ##=delword(##,_,1) /*pick card; delete it. */
@.cards=deck._ /*add it to the tableau.*/
do j=1 for words(@.cards) /*define cells for card.*/
@.cards.j=word(@.cards,j) /*define a cell for card*/
Line 1,869 ⟶ 1,878:
/*──────────────────────────────────DEFFEATURES subroutine──────────────*/
defFeatures: parse arg what,v; _=words(v) /*obtain what to define.*/
if _\==values then do; call
exit -1
end /* [↑] check for typos.*/
do k=1 for words(values) /*define all possibles. */
Line 1,907 ⟶ 1,916:
/*──────────────────────────────────FINDSETS subroutine─────────────────*/
findSets: parse arg n; call genPoss /*N: the number of sets to find.*/
do j=1 for p /*P is the # of possible sets. */
do f=1 for features
Line 1,929 ⟶ 1,938:
if \ok then iterate /*Is this set OK? Nope, skip it.*/
sets=sets+1 /*bump the number of sets found. */
end /*j*/
return
/*──────────────────────────────────SEY subroutine──────────────────────*/
sey: if \tell then return /*should output be suppressed? */
if arg(2)==. then say; say arg(1); if arg(3)==. then say; return</lang>
'''outpout''' when using the default input:
<pre>
dealing 9 cards:
card 1 one
card 2 two
card 3
card 4
card 5 two
card 6 two
card 7 two
card 8 three
card 9
set
set 2:
set 3:
set
4 sets found.
▲ set 1: two red squiggle solid ───── three green diamond striped ───── one purple oval open
▲ set 2: two red squiggle solid ───── three green diamond striped ───── one purple oval open
▲ set 3: two red squiggle solid ───── three green diamond striped ───── one purple oval open
▲ set 4: three green diamond striped ───── three green diamond striped ───── three green diamond striped
</pre>
|