diff options
| -rw-r--r-- | challenge-047/user-person/perl/ch-2.pl | 9 |
1 files 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 |
