Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make verbose progress output optional
  • Loading branch information
Paul Cochrane committed Apr 23, 2015
1 parent 8a59b65 commit 3ce582d
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions categories/euler/prob168-shlomif.pl
Expand Up @@ -20,25 +20,32 @@
=end pod

my $sum = 0;
# $multiplier is "d"
for 1 .. 9 -> $multiplier {
for 1 .. 99 -> $L {
# $digit is m.
for 1 .. 9 -> $digit {
my $n = (((10 ** $L - $multiplier)*$digit)/(10*$multiplier - 1));

my $number_to_check = $n * 10 + $digit;
if ($n.chars() == $L and ($multiplier * $number_to_check
== $n + $digit * 10 ** $L)) {
print "Found $number_to_check\n";
$sum += $number_to_check;
print "Sum = $sum\n";
sub MAIN(Bool :$verbose = False) {
my $sum = 0;
# $multiplier is "d"
for 1 .. 9 -> $multiplier {
for 1 .. 99 -> $L {
# $digit is m.
for 1 .. 9 -> $digit {
my $n = (((10 ** $L - $multiplier)*$digit)/(10*$multiplier - 1));

my $number_to_check = $n * 10 + $digit;
if ($n.chars() == $L and ($multiplier * $number_to_check
== $n + $digit * 10 ** $L)) {
print "Found $number_to_check\n" if $verbose;
$sum += $number_to_check;
print "Sum = $sum\n" if $verbose;
}
}
}
}
}

say "Last 5 digits of the final sum are: ", "$sum".substr(*-5);
if $verbose {
say "Last 5 digits of the final sum are: ", "$sum".substr(*-5);
}
else {
say "$sum".substr(*-5);
}
}

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit 3ce582d

Please sign in to comment.