Skip to content

Instantly share code, notes, and snippets.

Created February 9, 2012 03:51
Show Gist options
  • Save anonymous/1777135 to your computer and use it in GitHub Desktop.
Save anonymous/1777135 to your computer and use it in GitHub Desktop.
I believe I'm trying to access double arrays wrong. The code is not functional but I believe the logic is sound. Any advice?
#!/usr/bin/perl
my $range = 20;
my $minimum = 10;
my $random_number = (int(rand($range)) + $minimum);
my @array1 =([0..$random_number],[0..$random_number]);
my @array2 =([0..$random_number],[0..$random_number]);
my @solution =([0..$random_number], [0..$random_number]);
for(my $index1 = 0; $index1 < $random_number; $index1++){
for(my $index2 = 0; $index2 < $random_number; $index2++){
for(my $index3 = 0; $index3 < $random_number; $index3++){
@solution([$index1],[$index2]) += (@array1([$index1],[$index3]) * @array2([$index3],[$index2]));
}
}
}
for(my $index = 0; $index < $random_number; $index++){
for(my $nextIndex = 0; $nextIndex < $random_number; $nextIndex++){
say (@solution([$index],[$nextIndex]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment