Skip to content

Commit f329e29

Browse files
committed
Make output verbosity optional
1 parent cbdefc8 commit f329e29

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

categories/euler/prob036-xenu.pl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,23 @@
2727
# Because of memory leak in these versions, this code eats tens of gigabytes of RAM
2828
#
2929

30-
my $palindromNumbersSum = 0;
31-
loop (my $i = 1; $i <= 999999; $i+=2) {
32-
if ( ($i.flip == $i) && (sprintf('%b',$i).flip == sprintf('%b',$i)) ) {
33-
$palindromNumbersSum += $i;
30+
sub MAIN(Bool :$verbose = False) {
31+
my $palindromNumbersSum = 0;
32+
loop (my $i = 1; $i <= 999999; $i+=2) {
33+
if ( ($i.flip == $i) && (sprintf('%b',$i).flip == sprintf('%b',$i)) ) {
34+
$palindromNumbersSum += $i;
35+
}
36+
if $verbose {
37+
say "Checked $i of 999999 numbers" unless $i % 99999;
38+
}
39+
40+
}
41+
if $verbose {
42+
say "Number of double-base palindromes: $palindromNumbersSum";
43+
}
44+
else {
45+
say $palindromNumbersSum;
3446
}
35-
say "Checked $i of 999999 numbers" unless $i % 99999;
3647
}
37-
say "Number of double-base palindromes: $palindromNumbersSum";
3848

3949
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)