Hello monks (meant here in a unisex context)
I have several problem sets wherein I am needing to find the GCD (Greatest Common Divisor) between 2 large numbers. Now I wrote a program that took in the 2 numbers and printed out all the divisors of those numbers. The lists were very long however; so I thought to myself; self, you should make the program compare the 2 lists for the greatest common one, or at least for all the common ones. In this though I failed. The following is my code, and I was hoping one of the geniuses who oft roam the monestery could quickly see my problem and offer some suggestion. I am sure it is a very stupid mistake.
#!/usr/bin/perl
use strict;
my @thing;
my @thing1;
my $test=0;
my ($i,$j,$k,$arg1,$arg2);
while(my $argv=shift){
if($test==0){
$arg1=$argv;
}
if($test>0){
$arg2=$argv;
}
for($i=1;$i<=$argv;$i++){
if(!($argv%$i)){
if($test==0){
@thing[$i]=$i;
}
if($test>0){
@thing1[$i]=$i;
}
}
}
$test++;
}
for($j=0;$j<=$arg1;$j++){
for($k=0;$k<=$arg2;$k++){
if(@thing[$j] == @thing1[$k]){
print "A common divisor of $arg1 and $arg2 is: ". @thing[$j] . "\
+n";
}
}
}
~heise2k~