> I was looking at the implementation of the FY shuffle that I see in
> Perlfaq4, namely:
>
> sub fy1 {
> my $deck = shift; # $deck is a reference to an array
> my $i = @$deck;
> while (--$i) {
> my $j = int rand ($i+1);
> @$deck[$i,$j] = @$deck[$j,$i];
> }
> }
>
> And I thought "guh, that looks a bit off" -- notably, it dies when given an
> empty array.
Now I understand... that's why shuffle.pl failed the test suite. ;-) I tried to
extract the
algorithm from the FAQ textually, and then run it. It worked for manual checking -
but it is now
obvious now why it was rejected.
BTW: It wasn't intended to be a serious submission, dig it out from the list of
submissions from
that game (what was it called?). If we weren't in the middle of a golf tournament,
I'd suggest
golfing the technique :)
Jonathan Paton
__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com