Created
November 1, 2011 18:17
-
-
Save turugina/1331421 to your computer and use it in GitHub Desktop.
sicp exercise 4.42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v5.12; | |
use Math::Combinatorics qw/permute/; | |
use List::MoreUtils qw/mesh/; | |
use Data::Dumper; | |
my @vars = qw/Betty Ethel Joan Kitty Mary/; | |
my @values = 1..scalar @vars; | |
say Dumper([ | |
grep { | |
($_->{Kitty} == 2 xor $_->{Betty} == 3) | |
&& ($_->{Ethel} == 1 xor $_->{Joan} == 2) | |
&& ($_->{Joan} == 3 xor $_->{Ethel} == 5) | |
&& ($_->{Kitty} == 2 xor $_->{Mary} == 4) | |
&& ($_->{Mary} == 4 xor $_->{Betty} == 1) | |
} | |
map { +{ mesh(@vars, @$_) } } permute(@values) | |
]); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment