Here's a solution based on a regex. It may run a long time if you have 50 couples celebrating their 50th Christmas though.
#!/usr/bin/perl use strict; use warnings; my %people = ( jim => ['betty', 'claire'], betty => ['frank', 'jim' ], frank => ['claire', 'john' ], claire => ['john', 'betty' ], john => ['jim', 'frank' ], nancy => ['', '' ], # new girl ); my @names = keys %people; my $str = ""; my $re = ""; my $i; foreach my $name (@names) { $str .= "$name:"; my %not; @not {$name, @{$people {$name}}} = (); $str .= join "," => grep {!exists $not {$_}} @names; $str .= "\n"; $re .= ".*\\b"; $re .= "(?!\\$_)" for 1 .. $i ++; $re .= "(\\w+)\\b.*\n"; } if (my @a = $str =~ $re) { foreach my $name (@names) { printf "$name picks %s\n" => shift @a; } } else { print "No solution possible.\n"; } __END__ nancy picks frank john picks betty claire picks jim betty picks claire jim picks john frank picks nancy
Abigail
In reply to Re: Kris Kringle / Secret Santa
by Abigail-II
in thread Kris Kringle / Secret Santa
by BigLug
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |