Set, the card game: Difference between revisions
(New task: Set, the card game) |
m (→{{header|Quackery}}: tidied up code) |
||
Line 49: | Line 49: | ||
[ 3 /mod swap ] |
[ 3 /mod swap ] |
||
drop |
drop |
||
3 times join |
|||
nested join ] ] constant |
|||
shuffle swap split drop ] is cards ( n --> [ ) |
shuffle swap split drop ] is cards ( n --> [ ) |
||
Line 59: | Line 59: | ||
[ dip dup arrange |
[ dip dup arrange |
||
dup isset iff |
dup isset iff |
||
[ nested rot |
|||
join swap ] |
|||
else drop ] |
|||
drop ] is sets ( [ --> [ ) |
drop ] is sets ( [ --> [ ) |
||
Revision as of 08:16, 27 August 2023
You are encouraged to solve this task according to the task description, using any language you may know.
The card game, Set, is played with a pack of 81 cards, each of which depicts either one, two, or three diamonds, ovals, or squiggles. The symbols are coloured red, green, or purple, and the colouration is either solid, shaded, or open. No two cards are identical.
In the game a number of cards are layed out face up and the players try to identify "sets" within the cards.
A set is three cards where either the symbols on the cards are the same or they are all different, the number of symbols on the cards are all the same or all different, the colours are all the same or all different, and the colourations are all the same or all different.
For example, this is a set:
two solid green ovals one open green squiggle three striped green diamonds
because each card depicts a different symbol, the number of symbols on each card is different, the colours are all the same, and the colourations are all different.
This is not a set:
two solid purple ovals one open green squiggle three striped green diamonds
because two of the cards are green and one is purple, so the colours are neither all the same nor all different.
- task
- Create a representation of a pack of Set cards, shuffle it, select a specified number of cards from the pack and list them in the output.
- Identify the sets in the selected cards and list them.
- Also see
- The wikipedia article, Set (card game)
Quackery
transpose
is defined at Matrix transposition#Quackery.
comb
and arrange
are defined at Combinations#Quackery.
[ true swap transpose
witheach
[ 0 swap witheach +
3 mod 0 > if
[ not conclude ] ] ] is isset ( [ --> b )
[ [ [] 81 times
[ i 4 times
[ 3 /mod swap ]
drop
3 times join
nested join ] ] constant
shuffle swap split drop ] is cards ( n --> [ )
[ [] swap
dup size swap
3 rot comb
witheach
[ dip dup arrange
dup isset iff
[ nested rot
join swap ]
else drop ]
drop ] is sets ( [ --> [ )
[ unpack dup dip
[ [ table
$ "one"
$ "two"
$ "three" ] do echo$ sp
[ table
$ "solid"
$ "striped"
$ "open" ] do echo$ sp
[ table
$ "red"
$ "green"
$ "purple" ] do echo$ sp
[ table
$ "diamond"
$ "squiggle"
$ "oval" ] do echo$ ]
0 > if [ say "s" ]
cr ] is echocard ( [ --> )
[ dup cards swap
cr say "Cards dealt: " echo cr cr
dup witheach echocard
cr
sets dup size
say "Sets present: " echo cr cr
witheach
[ witheach echocard
cr ] ] is play ( n --> )
' [ 4 8 12 ] witheach
[ play say "-----" ]
- Output:
Cards dealt: 4 two striped green squiggles one open purple oval one solid purple diamond three open red diamonds Sets present: 0 ----- Cards dealt: 8 three open purple squiggles two open purple ovals three solid purple ovals three solid red squiggles two striped purple diamonds two solid green squiggles one striped green oval one open purple diamond Sets present: 1 three open purple squiggles two open purple ovals one open purple diamond ----- Cards dealt: 12 one solid green diamond one striped red diamond one open purple squiggle two solid green diamonds two striped green squiggles two solid red ovals two solid green squiggles one open green squiggle two solid green ovals two solid red diamonds one open purple diamond three striped purple diamonds Sets present: 3 two solid red ovals one open green squiggle three striped purple diamonds two solid green diamonds two solid green squiggles two solid green ovals one solid green diamond one striped red diamond one open purple diamond -----