Jump to content

Set puzzle: Difference between revisions

m
m (updating prolog to have the right number of sets produced)
m (→‎{{header|Tailspin}}: syntax update)
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.
<lang tailspin>
def deck: [ 1..3 -> \(def colour: $;
1..3 -> \(def symbol: $;
1..3 -> \(def number: $;
1..3 -> {colour: $colour, symbol: $symbol, number: $number, shading: $} !
\) !
\) !
\)
];
 
templates deal
@: $deck;
[ 1..$ -> \($@deal::length -> SYS::randomInt -> ^@deal($ + 1) !\)] !
end deal
 
Line 3,640:
$(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
<~[<~=3|=6|=9>]> $set !
end isSet
 
templates findSets
def hand: $;
[ 1..$hand::length - 2 -> \(def a: $;
$a+1..$hand::length - 1 -> \(def b: $;
$b+1..$hand::length -> $hand([$a, $b, $]) !
\) !
\) -> isSet ] !
end findSets
 
Line 3,702:
 
Twelve cards with six sets
<lang tailspin>
<pre>
[12,6] -> setPuzzle -> formatSets -> !OUT::write
</lang>
 
{{out}}
<pre>
hand:
red-oval-one-striped
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.