Skip to content

Instantly share code, notes, and snippets.

@skreuzer
Created February 19, 2013 21:17
Show Gist options
  • Save skreuzer/4990016 to your computer and use it in GitHub Desktop.
Save skreuzer/4990016 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
sub fisher_yates_shuffle
{
my $array = shift;
my $i = @$array;
while ( --$i )
{
my $j = int rand( $i + 1 );
@$array[$i,$j] = @$array[$j,$i];
}
}
sub main
{
my @players = (qw/ SK FB GY CB /);
my @boxes = (qw/ AA BB CC DD EE FF GG HH II JJ KK LL MM NN OO PP /);
my $player = 0;
my $board = undef;
fisher_yates_shuffle(\@players);
fisher_yates_shuffle(\@boxes);
$board .= $_ while(<DATA>);
foreach my $box (@boxes)
{
$board =~ s/$box/$players[$player]/;
$player = (++$player == scalar(@players)) ? 0 : $player;
}
print $board;
exit 0;
}
main();
__DATA__
00-14 15-29 30-44 45-59
+-----+-----+-----+-----+
8 | AA | BB | CC | DD |
+-----+-----+-----+-----+
9 | EE | FF | GG | HH |
+-----+-----+-----+-----+
10 | II | JJ | KK | LL |
+-----+-----+-----+-----+
11 | MM | NN | OO | PP |
+-----+-----+-----+-----+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment