From 969cdd46601603ba90c995072a79ade9572ad1f1 Mon Sep 17 00:00:00 2001 From: corvettes13 <86648326+corvettes13@users.noreply.github.com> Date: Thu, 2 Dec 2021 21:45:38 -0600 Subject: Create ch-1.pl --- challenge-141/paul-fajman/perl/ch-1.pl | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-141/paul-fajman/perl/ch-1.pl 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"; -- cgit