Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Set-puzzle/Raku/set-puzzle.raku
Normal file
28
Task/Set-puzzle/Raku/set-puzzle.raku
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
enum Color (red => 0o1000, green => 0o2000, purple => 0o4000);
|
||||
enum Count (one => 0o100, two => 0o200, three => 0o400);
|
||||
enum Shape (oval => 0o10, squiggle => 0o20, diamond => 0o40);
|
||||
enum Style (solid => 0o1, open => 0o2, striped => 0o4);
|
||||
|
||||
my @deck = Color.enums X Count.enums X Shape.enums X Style.enums;
|
||||
|
||||
sub MAIN($DRAW = 9, $GOAL = $DRAW div 2) {
|
||||
sub show-cards(@c) { { printf "%9s%7s%10s%9s\n", @c[$_;*]».key } for ^@c }
|
||||
|
||||
my @combinations = [^$DRAW].combinations(3);
|
||||
|
||||
my @draw;
|
||||
repeat until (my @sets) == $GOAL {
|
||||
@draw = @deck.pick($DRAW);
|
||||
my @bits = @draw.map: { [+] @^enums».value }
|
||||
@sets = gather for @combinations -> @c {
|
||||
take @draw[@c].item when /^ <[1247]>+ $/ given ( [+|] @bits[@c] ).base(8);
|
||||
}
|
||||
}
|
||||
|
||||
say "Drew $DRAW cards:";
|
||||
show-cards @draw;
|
||||
for @sets.kv -> $i, @cards {
|
||||
say "\nSet {$i+1}:";
|
||||
show-cards @cards;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue