Set puzzle: Difference between revisions

→‎{{header|Perl 6}}: for clarity use octal to set up original bits, masak++
(solution for immutable issue and optional shuffle)
(→‎{{header|Perl 6}}: for clarity use octal to set up original bits, masak++)
Line 435:
{{works with|rakudo|2013-02-11}}
This uses the <tt>combine</tt> routine from [[Combinations#Perl_6]] task. The trick here is to allocate three different bits for each enum, with the result that the cards of a matching set OR together to produce a 4-digit octal number that contains only the digits 1, 2, 4, or 7. This OR is done by funny looking <tt>[+|]</tt>, which is the reduction form of <tt>+|</tt>, which is the numeric bitwise OR. (Because Perl 6 stole the bare <tt>|</tt> operator for composing junctions instead.)
<lang perl6>enum Color (red => 5120o1000, green => 1024 0o2000, purple => 20480o4000);
enum Count (one => 64 0o100, two => 128 0o200, three => 256 0o400);
enum Shape (oval => 8 0o10, squiggle => 160o20, diamond => 32 0o40);
enum Style (solid => 1 0o1, open => 2 0o2, striped => 4 0o4);
 
my @deck := (Color.enums X Count.enums X Shape.enums X Style.enums).tree;
Anonymous user