diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-25 22:14:47 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-25 22:14:47 +0000 |
| commit | 7160c6fd2ad52dc7c7e117c1e59ff7de4821603e (patch) | |
| tree | fa508f0a615c21e18fe84c4bc999d19757476007 /challenge-192/mohammad-anwar/python | |
| parent | fb78e5b076d1a95a268ace12b169ad75e58cdf53 (diff) | |
| download | perlweeklychallenge-club-7160c6fd2ad52dc7c7e117c1e59ff7de4821603e.tar.gz perlweeklychallenge-club-7160c6fd2ad52dc7c7e117c1e59ff7de4821603e.tar.bz2 perlweeklychallenge-club-7160c6fd2ad52dc7c7e117c1e59ff7de4821603e.zip | |
- Added solutions to the task 1 of week 192.
Diffstat (limited to 'challenge-192/mohammad-anwar/python')
| -rw-r--r-- | challenge-192/mohammad-anwar/python/ch-1.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-192/mohammad-anwar/python/ch-1.py b/challenge-192/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..3ff80be425 --- /dev/null +++ b/challenge-192/mohammad-anwar/python/ch-1.py @@ -0,0 +1,32 @@ +#!/usr/bin/python3 + +''' + +Week 192: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-192 + +Task #1: Binary Flip + + You are given a positive integer, $n. + + Write a script to find the binary flip. + +''' + +import unittest + +def binaryFlip(n) -> int: + return int(''.join(['1' if i == '0' else '0' for i in "{0:b}".format(n)]),2) + +# +# +# Unit test class + +class TestBinaryFlip(unittest.TestCase): + def test_binaryFlip(self): + self.assertEqual(binaryFlip(5), 2, 'Example 1') + self.assertEqual(binaryFlip(4), 3, 'Example 2') + self.assertEqual(binaryFlip(6), 1, 'Example 3') + +unittest.main() |
