use strict; use List::Permutor; =head1 Stupid question A man left a legacy of $10,000 to three relatives and their wives. Together, the wives received $3960. June received $100 more than Camille, and Martha received $100 more than June. Jack Smith was given just as much as his wife, Horace Saunders got half as much again as his wife, and Terry Conners received twice as much as his wife. What was the first name of each man's wife? =cut # there is $300 difference between # the most and least given each wife # so we subtract the 300 and divide by for # 3 for the base point for each wife my $total_for_wives = 3960; my $am = (($total_for_wives - 300) / 3); my %wives = ( Camille => $am, June => $am + 100, Martha => $am + 200, ); my @wives_combo; my $perm = List::Permutor->new( sort keys %wives ); while (my @set = $perm->next) { push ( @wives_combo , \@set) ; } my %husbands = ( 'Terry Conners' => 2 , 'Horace Saunders' => 1.5 , 'Jack Smith' => 1 ); foreach my $array (@wives_combo) { my $total; my $count; foreach (sort { $b <=> $a } values %husbands ) { $total += ($wives{$array->[$count++]} * $_); } if ( ($total += $total_for_wives) == 10000) { my $num; foreach (sort { $husbands{$b} <=> $husbands{$a} } keys %husbands) { printf "$_ wife's name is: $array->[$num++]\n"; } last; } }