Skip to content

Instantly share code, notes, and snippets.

@turugina
Created November 1, 2011 18:17
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 turugina/1331421 to your computer and use it in GitHub Desktop.
Save turugina/1331421 to your computer and use it in GitHub Desktop.
sicp exercise 4.42
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