Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 27 lines (21 sloc) 0.45 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;

sub is_palindrome {
    my ($n) = @_;

    my $length = length($n);
    foreach my $d ( 0 .. $length / 2 ) {
        if ( substr( $n, $d, 1 ) ne substr( $n, $length - $d - 1, 1 ) ) {
            return 0;
        }
    }

    return 1;
}

my $sum;

foreach my $n ( 1 .. 999_999 ) {
    if ( is_palindrome($n) && is_palindrome( sprintf( '%b', $n ) ) ) {
        $sum += $n;
    }
}

say $sum;
Something went wrong with that request. Please try again.