I hesitated to post a reply since even the poster admits it looks like homework. However my curiousity took over and I decided to write a program to solve the problem.
Since it isn't homework I used an external module that does the permutations for me List::Permutor.
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 Smit +h 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; } }
Update: Code has been replaced after a bug was spotted by Anonymous Monk.

In reply to Re: Passing a complex array to a function by trs80
in thread Passing a complex array to a function by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.