in reply to Re: Kris Kringle / Secret Santa
in thread Kris Kringle / Secret Santa

Yeah this is all very very easy:
my @names = qw/andy betty craig daniel edith/; my %reverse_lookup; @reverse_lookup{ @names } = (0..4); foreach $year (2004 .. 2007) { foreach (sort keys %people) { printf("%04d: %s buys for %s\n", $year, $_, $names[ ($year+$reverse_lookup{$_}) % 4 + 1] ); } }
However, the group isn't constant. My original data introduces nancy after two years, if we suddenly do this then a latin square doesn't work.

Also, I must point out that there will be data such as sally can never buy for derek ... not after last years christmas party. So derek is on sally's list .. permanently. Even after we reset it at the end of the cycle.

Replies are listed 'Best First'.
Re^3: Kris Kringle / Secret Santa
by tall_man (Parson) on Jan 10, 2004 at 23:32 UTC
    I saw the addition of Nancy after two years in your original data, but I chose to ignore it because it makes a full solution impossible. Suppose we wanted to continue the pattern for the next four years. Andy, Betty, Craig, Daniel, and Edith each want to buy something for Nancy (and for the other three they have not bought for yet) before they go back to anyone earlier on their list. That's five buyers for Nancy in four years, which won't work.

    I think the best you can do when a new person is added is to compute a new latin square from that point and try to place the previous pairings as low in the square as you can.

    I also think I could prove that having one person who cannot buy for another also makes a full cycle impossible. In that case, you could place that pairing on the last line of the latin square, and start a new square when you get to that point.