diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-10-29 14:41:00 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-10-29 14:41:00 +0100 |
| commit | bf8032b503c262609b9b77e60ed56864a4546aed (patch) | |
| tree | 2ae6fea24887f1dbdacf9aba9cceffb1b521a07d | |
| parent | f58e9e88056887a42482592154c1c7cbe03e61cb (diff) | |
| download | perlweeklychallenge-club-bf8032b503c262609b9b77e60ed56864a4546aed.tar.gz perlweeklychallenge-club-bf8032b503c262609b9b77e60ed56864a4546aed.tar.bz2 perlweeklychallenge-club-bf8032b503c262609b9b77e60ed56864a4546aed.zip | |
Add Python solution
| -rw-r--r-- | challenge-118/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-118/paulo-custodio/python/ch-1.py | 27 | ||||
| -rw-r--r-- | challenge-118/paulo-custodio/test.pl | 4 |
3 files changed, 29 insertions, 4 deletions
diff --git a/challenge-118/paulo-custodio/Makefile b/challenge-118/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-118/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-118/paulo-custodio/python/ch-1.py b/challenge-118/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..b7652634d3 --- /dev/null +++ b/challenge-118/paulo-custodio/python/ch-1.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +# Challenge 118 +# +# TASK #1 - Binary Palindrome +# Submitted by: Mohammad S Anwar +# 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. + +import sys + +N = int(sys.argv[1]) +bits = "{:b}".format(N) +rbits = bits[::-1] +if bits==rbits: + print(1) +else: + print(0) diff --git a/challenge-118/paulo-custodio/test.pl b/challenge-118/paulo-custodio/test.pl deleted file mode 100644 index ba6c37260b..0000000000 --- a/challenge-118/paulo-custodio/test.pl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env perl -use Modern::Perl; -use Test::More; -require '../../challenge-001/paulo-custodio/test.pl'; |
