From ca0bcb9dc1b66cbb1fefa71b8e647614f640bfb4 Mon Sep 17 00:00:00 2001 From: user-person <60802990+user-person@users.noreply.github.com> Date: Sun, 16 Feb 2020 04:26:01 -0500 Subject: Update ch-2.pl --- challenge-047/user-person/perl/ch-2.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/challenge-047/user-person/perl/ch-2.pl b/challenge-047/user-person/perl/ch-2.pl index 1e9d4c4f65..a501321878 100644 --- a/challenge-047/user-person/perl/ch-2.pl +++ b/challenge-047/user-person/perl/ch-2.pl @@ -27,17 +27,22 @@ sub firstDigit { while ($number >= 10) { $number /= 10; } - return $number; + return int($number); } for (my $i = 100; $count < $QUANTITY ; ++$i) { $first = firstDigit $i; $last = $i % 10; + my $formedBy = ($first * 10) + $last; - if ( $i % $first == 0 && ($last == 0 || $i % $last == 0 )) { + if ( $i % $formedBy == 0 ) { print "$i "; ++$count; } } print "\n"; + +__END__ +output: + 100 105 108 110 120 121 130 132 135 140 143 150 154 160 165 170 176 180 187 190 -- cgit