sub fys {
my $arr = shift;
my $i = @{ $arr };
while ( $i ) {
my $j = int rand $i;
@$arr[$i,$j] = @$arr[$j,$i];
--$i;
}
}
####
@nums = map [ @{$_}[@cols] ], @nums;
####
my @cols = 0..11;
do {
fys( \@cols );
} until is_deranged( \@cols );
####
sub is_deranged {
my $arr = shift;
$arr->[ $_ ] == $_ and return for 0..$#$arr;
return 1;
}
####
use strict;
use warnings;
my @cols = qw/0 1 2 3 4 5 6 7 8 9 10 11/;
fys( \@cols );
my @nums = ( [qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
[qw/01 02 03 04 05 06 07 08 09 10 11 12/],
);
@nums = map [ @{$_}[@cols] ], @nums;
# for( my $i = 0; $i < 12; $i++) {
# for( my $j = 0; $j < 6; $j++) {
# ($nums[$i][ $cols[$j] ], $nums[$i][ $cols[$j+6] ]) = ($nums[$i][ $cols[$j+6] ], $nums[$i][ $cols[$j] ]);
# }
# }
&printit;
sub printit() {
for( my $i = 0; $i < 12; $i++) {
print "@{ $nums[$i] } ";
print "\n";
}
}
sub fys {
my $arr = shift;
my $i;
for( $i = @{ $arr }; $i--;) {
# my $j = int rand ($i + 1);
my $j = int rand $i;
next if $i == $j;
@$arr[$i,$j] = @$arr[$j,$i];
}
}