diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-10-15 21:18:31 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2020-10-15 21:18:31 +0100 |
| commit | 0cd99e2e04092614f1f11c64e05afa43a1b84518 (patch) | |
| tree | a351ec1660b8628f22601a52ece8ddcd07c7e9cb | |
| parent | 6bef3ae31942f9cf6d3a10668dc72026e78f99d7 (diff) | |
| parent | bcbf8580f8ce6eb65debdd5c3768efbdd43d721a (diff) | |
| download | perlweeklychallenge-club-0cd99e2e04092614f1f11c64e05afa43a1b84518.tar.gz perlweeklychallenge-club-0cd99e2e04092614f1f11c64e05afa43a1b84518.tar.bz2 perlweeklychallenge-club-0cd99e2e04092614f1f11c64e05afa43a1b84518.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
| -rw-r--r-- | challenge-082/vinod-k/perl/ch-1.pl | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-082/vinod-k/perl/ch-1.pl b/challenge-082/vinod-k/perl/ch-1.pl new file mode 100644 index 0000000000..395cdc1a5e --- /dev/null +++ b/challenge-082/vinod-k/perl/ch-1.pl @@ -0,0 +1,32 @@ +use strict; +use warnings; + +my ($a, $b) = @ARGV; + +die "Please enter two positive numbers: $!" unless (@ARGV && $#ARGV >= 1); + +my %seen; +my (@a, @b, @final); + +foreach my $i (1..$a+1){ + if( $a % $i == 0){ + push (@a, $i); + } +} + +foreach my $j (1..$b+1){ + if( $b % $j == 0){ + push (@b, $j); + } +} + +@seen{@a} = (); + +foreach my $new ( @b ) { + push (@final, $new ) if exists $seen{$new}; +} + +print "Common factors in $a and $b are:\n"; +foreach (@final){ + print "$_\n" +} |
