Skip to content

Instantly share code, notes, and snippets.

@abraxxa
Created January 14, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abraxxa/58c1123ca6a03cb54808 to your computer and use it in GitHub Desktop.
Save abraxxa/58c1123ca6a03cb54808 to your computer and use it in GitHub Desktop.
Brain Twister #13 solved with Perl 6
#!perl6
use v6.c;
my @pots[12] = (
<d 1 o d 1>,
<k 2 d d 2>,
<v 1 o p 3>,
<v 1 h s 4>,
<v 1 o s 5>,
<d 1 h s 6>,
<d 1 h p 7>,
<k 3 o s 8>,
<v 1 h p 9>,
<k 2 d p 10>,
<v 3 h p 11>,
<d 2 d d 12>,
);
sub is-match(List $_) returns Bool {
return ( (
( .[0][0] eq .[1][0] eq .[2][0] )
|| ( .[0][0], .[1][0], .[2][0] ).Bag.elems == 3
)
&& (
( .[0][1] eq .[1][1] eq .[2][1] )
|| ( .[0][1], .[1][1], .[2][1] ).Bag.elems == 3
)
&& (
( .[0][2] eq .[1][2] eq .[2][2] )
|| ( .[0][2], .[1][2], .[2][2] ).Bag.elems == 3
)
&& (
( .[0][3] eq .[1][3] eq .[2][3] )
|| ( .[0][3], .[1][3], .[2][3] ).Bag.elems == 3
)
);
}
@pots.combinations(3).grep(&is-match).say;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment