aboutsummaryrefslogtreecommitdiff
path: root/challenge-118/lance-wicks/perl/lib/Binary/Palindrome.pm
blob: 1b752cf9e2b38a0f5f6668a8329f47e520c1bca1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package Binary::Palindrome;

use Moo;

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

    my $bin = $self->represent_as_binary($n);
    my $rev = reverse $bin;

    if   ( $rev eq $bin ) { return 1 }
    else                  { return 0 }
}

sub represent_as_binary {
    my ( $self, $n ) = @_;
    return sprintf( "%b", $n );
}

1;