aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wilson <steven1170@zoho.eu>2021-06-22 12:58:29 +0100
committerSteven Wilson <steven1170@zoho.eu>2021-06-22 12:58:29 +0100
commitb009a91c2e7296dfbed961a5b5fb643be55984d0 (patch)
treee79d83fd8c8eca0ed0a084d6956573a4e3dd471e
parent2f409d0f142e38f1f30d9acbae48eb10e7c71461 (diff)
downloadperlweeklychallenge-club-b009a91c2e7296dfbed961a5b5fb643be55984d0.tar.gz
perlweeklychallenge-club-b009a91c2e7296dfbed961a5b5fb643be55984d0.tar.bz2
perlweeklychallenge-club-b009a91c2e7296dfbed961a5b5fb643be55984d0.zip
add week 118 challenge 1 in perl
-rwxr-xr-xchallenge-118/steven-wilson/perl/ch-1.pl23
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;
+ }
+}