diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-12-03 11:22:10 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-03 11:22:10 +0000 |
| commit | 2379f0f5e6edef92837c02fa808216d9a46c3578 (patch) | |
| tree | 196a9832f66222c99b02c0285a1c98a6eb49693e | |
| parent | c7e55a6edc9aa43d018b75ac392cc5a9723dccd8 (diff) | |
| parent | 969cdd46601603ba90c995072a79ade9572ad1f1 (diff) | |
| download | perlweeklychallenge-club-2379f0f5e6edef92837c02fa808216d9a46c3578.tar.gz perlweeklychallenge-club-2379f0f5e6edef92837c02fa808216d9a46c3578.tar.bz2 perlweeklychallenge-club-2379f0f5e6edef92837c02fa808216d9a46c3578.zip | |
Merge pull request #5319 from corvettes13/patch-12
Create ch-1.pl
| -rw-r--r-- | challenge-141/paul-fajman/perl/ch-1.pl | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-141/paul-fajman/perl/ch-1.pl b/challenge-141/paul-fajman/perl/ch-1.pl new file mode 100644 index 0000000000..ff516d1b5f --- /dev/null +++ b/challenge-141/paul-fajman/perl/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/perl + +# Weekly Challenge 141 Task 1 +# +# Write a script to find lowest 10 positive integers having exactly 8 divisors. + +use strict; + +my @numbers; +my @final; +my $i=8; +my $j=1; + +# Loop through until 8 numbers are found. +while ($#final < 7) { + # Loop through all possible divisors. Must + # go through all of them up to the number + # being tested to ensure there are only 8. + for ($j=1; $j<=$i; $j++) { + if (($i % $j) eq 0) { + push @numbers, $i; + } + } + push @final, $i if $#numbers == 7; + $i++; + undef(@numbers); +} + +print "The first 8 integers to have exactly 8 divisors:\n@final\n"; |
