Double-base Palindromes

By Ziddykins on Jun 02, 2014

Palindromes are neat.
Palindromic numbers in base 10 as well as base 2 are even more neat!
Enter a max value and it'll do the rest.
(note: Base10 is human-readable numbers, where Base2 is binary)

#!/usr/bin/perl
use warnings;
use strict;

my $sum;
print "Max value: ";
my $length = <STDIN>;

for(my $i=1; $i<$length; $i++) {
    my $bnum = sprintf("%b", $i);
    if ($i == reverse($i)
    && $bnum == reverse($bnum)) {
        print "$i:$bnum\n";
    }
}

Comments

Sign in to comment.
Hawkee   -  Jun 03, 2014

Some good basic examples of perl. It's been years since I've used perl, but it was my introduction to web development.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.