Set puzzle: Difference between revisions
Content added Content deleted
m (updating prolog to have the right number of sets produced) |
m (→{{header|Tailspin}}: syntax update) |
||
Line 3,621: | Line 3,621: | ||
Dealing cards at random to the size of the desired hand, then trying again if the desired set count is not achieved. |
Dealing cards at random to the size of the desired hand, then trying again if the desired set count is not achieved. |
||
<lang tailspin> |
<lang tailspin> |
||
def deck: [ 1..3 -> (def colour: $; |
def deck: [ 1..3 -> \(def colour: $; |
||
1..3 -> (def symbol: $; |
1..3 -> \(def symbol: $; |
||
1..3 -> (def number: $; |
1..3 -> \(def number: $; |
||
1..3 -> {colour: $colour, symbol: $symbol, number: $number, shading: $} ! |
1..3 -> {colour: $colour, symbol: $symbol, number: $number, shading: $} ! |
||
) ! |
\) ! |
||
) ! |
\) ! |
||
) |
\) |
||
]; |
]; |
||
templates deal |
templates deal |
||
@: $deck; |
@: $deck; |
||
[ 1..$ -> ($@deal::length -> SYS::randomInt -> ^@deal($ + 1) !)] ! |
[ 1..$ -> \($@deal::length -> SYS::randomInt -> ^@deal($ + 1) !\)] ! |
||
end deal |
end deal |
||
Line 3,640: | Line 3,640: | ||
$(1).number + $(2).number + $(3).number, $(1).shading + $(2).shading + $(3).shading ] -> # |
$(1).number + $(2).number + $(3).number, $(1).shading + $(2).shading + $(3).shading ] -> # |
||
// if it is not an array that contains an element that is not 3, 6 or 9, it is a set |
// if it is not an array that contains an element that is not 3, 6 or 9, it is a set |
||
<~[<~3|6|9>]> $set ! |
<~[<~=3|=6|=9>]> $set ! |
||
end isSet |
end isSet |
||
templates findSets |
templates findSets |
||
def hand: $; |
def hand: $; |
||
[ 1..$hand::length - 2 -> (def a: $; |
[ 1..$hand::length - 2 -> \(def a: $; |
||
$a+1..$hand::length - 1 -> (def b: $; |
$a+1..$hand::length - 1 -> \(def b: $; |
||
$b+1..$hand::length -> $hand([$a, $b, $]) ! |
$b+1..$hand::length -> $hand([$a, $b, $]) ! |
||
) ! |
\) ! |
||
) -> isSet ] ! |
\) -> isSet ] ! |
||
end findSets |
end findSets |
||
Line 3,702: | Line 3,702: | ||
Twelve cards with six sets |
Twelve cards with six sets |
||
<lang tailspin> |
|||
⚫ | |||
[12,6] -> setPuzzle -> formatSets -> !OUT::write |
[12,6] -> setPuzzle -> formatSets -> !OUT::write |
||
</lang> |
|||
{{out}} |
|||
⚫ | |||
hand: |
hand: |
||
red-oval-one-striped |
red-oval-one-striped |