diff options
| -rwxr-xr-x | challenge-118/steven-wilson/perl/ch-1.pl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-118/steven-wilson/perl/ch-1.pl b/challenge-118/steven-wilson/perl/ch-1.pl new file mode 100755 index 0000000000..6fa9a6bc1c --- /dev/null +++ b/challenge-118/steven-wilson/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Test::More; + +ok( is_binary_palindrome(5) == 1, + "Output: 1 as binary representation of 5 is 101 which is Palindrome." ); +ok( is_binary_palindrome(4) == 0, + "Output: 0 as binary representation of 4 is 100 which is NOT Palindrome." +); +done_testing(); + +sub is_binary_palindrome { + my $integer = shift; + my $binary = sprintf( "%b", $integer ); + if ( $binary eq reverse $binary ) { + return 1; + } + else { + return 0; + } +} |
