Created
May 3, 2013 16:59
-
-
Save jadeallenx/5511256 to your computer and use it in GitHub Desktop.
Unzip, permute second list, rezip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! perl | |
use List::Util qw(shuffle); | |
use Data::Dumper; | |
my @input = ( [ 'a', 1 ], [ 'b', 1 ], [ 'c', 2 ], [ 'd', 2 ] ); | |
my @element_1s = map { $_->[0] } @input; | |
my @element_2s = map { $_->[1] } @input; | |
my @random_2s = shuffle @element_2s; | |
my @final; | |
for ( my $i = 0; $i < $#input + 1; $i++ ) { | |
my $t = [ $element_1s[$i], $random_2s[$i] ]; | |
push @final, $t; | |
} | |
print Dumper @final; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment