Last active
August 29, 2015 14:27
-
-
Save laszlo91/0d8cc77982f9b3a1bd81 to your computer and use it in GitHub Desktop.
Help to fill big matrix and check the correctness. See into the code for more information.
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
#by Muhammad Khattab and Filippo Bonora | |
#for nlpspoiler.it | |
#STDIN: your incomplete matrix, something like B C D | |
# | |
# B 1 | |
# | |
# C 7 1 | |
# | |
# D 5 2 1 | |
#STDOUT: your complete matrix: B C D | |
# | |
# B 1 7 5 | |
# | |
# C 7 1 2 | |
# | |
# D 5 2 1 | |
# with the list of possible errors made during compilation | |
use strict; | |
use warnings; | |
# put the matrix in a complex structure (array of array) | |
my @array; | |
my $c =0; | |
while (my $line = <STDIN>){ | |
my $n=0; | |
chomp $line; | |
while ($line=~/(.*?)($|\t)/g){ | |
$array[$c][$n] = $1; | |
$n++; | |
} | |
$c++; | |
} | |
# if in the case x/y there's a number and in the case y/x there's nothing, copy x/y case content in y/x | |
for (my $i =0; $i<= $#array; $i++){ | |
for (my $k=0; $k<=$#array; $k++){ | |
if ($array[$i][$k] eq '' and $array[$k][$i] ne ''){ | |
print $array[$k][$i], "\t"; | |
} | |
else { | |
print $array[$i][$k], "\t"; | |
} | |
} | |
print "\n"; | |
} | |
# checking of errors if there are | |
for (my $i =0; $i<= $#array; $i++){ | |
for (my $k=0; $k<=$#array; $k++){ | |
if ($array[$i][$k] !~ $array[$k][$i] ) { | |
print "check case ", $i+1, "-", $k+1, " and its twin 'cause they don't match each other\n";}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment