in reply to Gift Exchange Code
should do it.die "No match possible" if @people % 2 or @people == 2 and %so_s; %reverse_so_s = reverse %so_s; @keys = keys %so_s; @values = values %so_s; @singles = grep { ! ( exists $so_s{$_} or exists $reverse_so_s{$_} ) } + @people; %matches = ( @keys, @singles, @values );
UPDATE: Oops, CountZero posted a very similar solution already. Much of my set-up is designed just to construct his or her @array1 and @array2.
UPDATE 2: Oops again. This dies far too often. (For example, it thinks that no match is possible if a, b, and c are affianced to d, e, and f, respectively, whereas that is not the case.) A few minutes' thought didn't show how to fix this without serious re-jiggering.
UPDATE 3: Third time's a charm, I hope. (Hey, maybe this is why people use modules instead of worrying about edge cases in their own code, huh?)
|
|---|