aboutsummaryrefslogtreecommitdiff
path: root/challenge-118
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-06-27 18:25:56 +0100
committerGitHub <noreply@github.com>2021-06-27 18:25:56 +0100
commit7ea6580f5d4384b5e19cb0e0bd3d4007f23fc7c5 (patch)
tree1969afb7f45f32da3730c40f0f16fe5fd4f654dd /challenge-118
parent4640bad216e05585f8578664c4e6a719e85d46c2 (diff)
parentd11966ab0d3cb39a9f730de9d3d1f584977646a9 (diff)
downloadperlweeklychallenge-club-7ea6580f5d4384b5e19cb0e0bd3d4007f23fc7c5.tar.gz
perlweeklychallenge-club-7ea6580f5d4384b5e19cb0e0bd3d4007f23fc7c5.tar.bz2
perlweeklychallenge-club-7ea6580f5d4384b5e19cb0e0bd3d4007f23fc7c5.zip
Merge pull request #4351 from wanderdoc/master
Solution to task#1 challenge-118
Diffstat (limited to 'challenge-118')
-rw-r--r--challenge-118/wanderdoc/perl/ch-1.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-118/wanderdoc/perl/ch-1.pl b/challenge-118/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..6e77df1851
--- /dev/null
+++ b/challenge-118/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,24 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+You are given a positive integer $N.
+Write a script to find out if the binary representation of the given integer is Palindrome. Print 1 if it is otherwise 0.
+Example Input: $N = 5
+Output: 1 as binary representation of 5 is 101 which is Palindrome.
+Input: $N = 4
+Output: 0 as binary representation of 4 is 100 which is NOT Palindrome.
+=cut
+
+
+
+
+
+sub dec_to_bin { return sprintf("%b",$_[0]); }
+sub is_palindrome { return $_[0] eq reverse($_[0]) ? 1 : 0 ; }
+
+for my $num ( 1 .. 255)
+{
+ print join("\t", $num, dec_to_bin($num), is_palindrome(dec_to_bin($num))), $/;
+} \ No newline at end of file