Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make output verbosity optional
  • Loading branch information
Paul Cochrane committed Apr 23, 2015
1 parent cbdefc8 commit f329e29
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions categories/euler/prob036-xenu.pl
Expand Up @@ -27,13 +27,23 @@
# Because of memory leak in these versions, this code eats tens of gigabytes of RAM
#

my $palindromNumbersSum = 0;
loop (my $i = 1; $i <= 999999; $i+=2) {
if ( ($i.flip == $i) && (sprintf('%b',$i).flip == sprintf('%b',$i)) ) {
$palindromNumbersSum += $i;
sub MAIN(Bool :$verbose = False) {
my $palindromNumbersSum = 0;
loop (my $i = 1; $i <= 999999; $i+=2) {
if ( ($i.flip == $i) && (sprintf('%b',$i).flip == sprintf('%b',$i)) ) {
$palindromNumbersSum += $i;
}
if $verbose {
say "Checked $i of 999999 numbers" unless $i % 99999;
}

}
if $verbose {
say "Number of double-base palindromes: $palindromNumbersSum";
}
else {
say $palindromNumbersSum;
}
say "Checked $i of 999999 numbers" unless $i % 99999;
}
say "Number of double-base palindromes: $palindromNumbersSum";

# vim: expandtab shiftwidth=4 ft=perl6

0 comments on commit f329e29

Please sign in to comment.