aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruser-person <60802990+user-person@users.noreply.github.com>2020-02-14 20:19:25 -0500
committerGitHub <noreply@github.com>2020-02-14 20:19:25 -0500
commit0323c8193223144fc99960c51b1640bc4203b8d9 (patch)
tree4b6dd830d8494a148692174378230e9cada2cd05
parent151d458b10d4ca145abbfcc45b801504618a69f6 (diff)
downloadperlweeklychallenge-club-0323c8193223144fc99960c51b1640bc4203b8d9.tar.gz
perlweeklychallenge-club-0323c8193223144fc99960c51b1640bc4203b8d9.tar.bz2
perlweeklychallenge-club-0323c8193223144fc99960c51b1640bc4203b8d9.zip
Create ch-2.pl
-rw-r--r--challenge-047/user-person/perl/ch-2.pl43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-047/user-person/perl/ch-2.pl b/challenge-047/user-person/perl/ch-2.pl
new file mode 100644
index 0000000000..1e9d4c4f65
--- /dev/null
+++ b/challenge-047/user-person/perl/ch-2.pl
@@ -0,0 +1,43 @@
+#!/usr/bin/env perl
+
+###########################################################################
+# script name: ch-2.pl #
+# #
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-047/ #
+# #
+# Write a script to print first 20 Gapful Numbers greater than or equal #
+# to 100. #
+# #
+# https://oeis.org/A108343 #
+# #
+# numbers that are divisible by the number formed by their first and last #
+# digit. #
+# #
+###########################################################################
+
+use strict;
+use warnings;
+
+my $QUANTITY = 20;
+my ($first, $last);
+my $count = 0;
+
+sub firstDigit {
+ my $number = $_[0];
+ while ($number >= 10) {
+ $number /= 10;
+ }
+ return $number;
+}
+
+for (my $i = 100; $count < $QUANTITY ; ++$i) {
+
+ $first = firstDigit $i;
+ $last = $i % 10;
+
+ if ( $i % $first == 0 && ($last == 0 || $i % $last == 0 )) {
+ print "$i ";
+ ++$count;
+ }
+}
+print "\n";