diff options
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() |
