Set, the card game: Difference between revisions

m
Moved Raku and Ruby entries into alphabetic order.
m (Moved Raku and Ruby entries into alphabetic order.)
Line 934:
----
</pre>
 
=={{header|Quackery}}==
 
Why does <code>isset</code>, the word that tests if three cards constitute a set, use <code>+</code> and <code>mod</code>?
 
If we map any of the properties, say colour, onto the numbers 0, 1 and 2, then the sum of three colours mod 3 is 0 if and only if all the colours are different or all the colours are the same. This can be confirmed exhaustively, or for the underlying mathematics see the first two paragraphs of the section "A Mathematical Perspective" (pages 7 and 8) in this paper:
 
::[https://web.math.princeton.edu/~charchan/SET.pdf SETs and Anti-SETs: The Math Behind the Game of SET, by Charlotte Chan]
 
<code>transpose</code> is defined at [[Matrix transposition#Quackery]].
 
<code>comb</code> and <code>arrange</code> are defined at [[Combinations#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ true swap transpose witheach
[ 0 swap witheach +
3 mod 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$ ]
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 "-----" ]</syntaxhighlight>
 
{{out}}
 
<pre>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
 
-----</pre>
 
=={{header|Raku}}==
Line 1,088 ⟶ 1,202:
</pre>
 
=={{header|Quackery}}==
 
Why does <code>isset</code>, the word that tests if three cards constitute a set, use <code>+</code> and <code>mod</code>?
 
If we map any of the properties, say colour, onto the numbers 0, 1 and 2, then the sum of three colours mod 3 is 0 if and only if all the colours are different or all the colours are the same. This can be confirmed exhaustively, or for the underlying mathematics see the first two paragraphs of the section "A Mathematical Perspective" (pages 7 and 8) in this paper:
 
::[https://web.math.princeton.edu/~charchan/SET.pdf SETs and Anti-SETs: The Math Behind the Game of SET, by Charlotte Chan]
 
<code>transpose</code> is defined at [[Matrix transposition#Quackery]].
 
<code>comb</code> and <code>arrange</code> are defined at [[Combinations#Quackery]].
 
<syntaxhighlight lang="Quackery"> [ true swap transpose witheach
[ 0 swap witheach +
3 mod 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$ ]
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 "-----" ]</syntaxhighlight>
 
{{out}}
 
<pre>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
 
-----</pre>
 
=={{header|Wren}}==
1,493

edits