'Drawing Names' for Christmas, Revisited
Okay, so, Randal had some good things to say (and they're incoporated into the code, below). One bug was pointed out: a state could arise where the last recipient is also the last giver, and that'll make the program go into an infinite loop. However, that was statistically improbable, given that my family is quite large. But, I'll sleep better at night, knowing that that is no longer the case - that the infinite loop might occur; not that my family isn't still large; although some of them are large unto themselves; but I digress.
However, my esteemed colleague, in an effort to not actually have to think for himself (since he was no doubt drunk on the many root beers he left lying around the Hodges' house), blindly copied this bug - and that was the means by which my legal team was able to instigate litigation - not unlike "dead" code in ROM. I guess this is probably typical for Lisp apologists.
In a (fruitless) effort to redeem himself, this aforementioned colleague just doubled the size of his code to hide the problem. Supposedly he fixed it. But, he has yet to provide any simple instructions on how to run it. ("Start by installing emacs *three days later* ... now, step 2 ...."). And with ((all (((of (those) (parenthesis) who)) can) tell))? :-) Sigh. The retribution I will take for this will be unending. But just look at how his code flows outside the boundaries of the text area. Ridiculous.
This program is now entering its 5th year of production use, and I give you version 2.0:
#!/usr/bin/perl -w
use strict;
my @names = qw(Curtis Kevin Natalie Aimee);
my @rcpts = @names;
for my $sndr (@names) {
my $rcpt = splice @rcpts, rand @rcpts, 1;
if ($sndr eq $rcpt ||
(1 == @rcpts && $rcpts[0] eq $names[$#names])) {
push @rcpts, $rcpt;
redo;
}
print "$sndr drew $rcpt\n";
}
May this version bring you a merrier Christmas.
Update: I thought of a good "to a man with a hammer..." equivalent for Lisp: "to a man with only a shift key and nine and a zero...."