aboutsummaryrefslogtreecommitdiff
path: root/challenge-192/mohammad-anwar/python/ch-1.py
blob: 0dac54c65ffcfc8a1be383920ecb22fbf27b404f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/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()