diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2021-07-17 12:43:34 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2021-07-17 12:43:34 +0200 |
| commit | 0949e4f44fa8b435ae4b54c6bfb0fee3813b9481 (patch) | |
| tree | cfaedbaa56ab7d9ad8e74fe7cff2be3452e2d38d /challenge-121/lubos-kolouch/python | |
| parent | 0908914dd492436c49889de5272685c550b8e32e (diff) | |
| download | perlweeklychallenge-club-0949e4f44fa8b435ae4b54c6bfb0fee3813b9481.tar.gz perlweeklychallenge-club-0949e4f44fa8b435ae4b54c6bfb0fee3813b9481.tar.bz2 perlweeklychallenge-club-0949e4f44fa8b435ae4b54c6bfb0fee3813b9481.zip | |
Challenge 121 Task 1 LK Perl Python
Diffstat (limited to 'challenge-121/lubos-kolouch/python')
| -rw-r--r-- | challenge-121/lubos-kolouch/python/ch-1.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/challenge-121/lubos-kolouch/python/ch-1.py b/challenge-121/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..0e41d3a501 --- /dev/null +++ b/challenge-121/lubos-kolouch/python/ch-1.py @@ -0,0 +1,20 @@ +# =============================================================================== +# DESCRIPTION: Perl Weekly Challenge #121 +# Task 1 - Invert bit +# +# AUTHOR: Lubos Kolouch +# CREATED: 20210710 04:44:33 PM +# =============================================================================== + + +def invert_bit(what: int, n: int): + + binary_what = str(bin(what)[2:]) + + binary_arr = list(binary_what) + binary_arr[-n] = '0' if binary_arr[-n] == '1' else '1' + return int("".join(binary_arr), 2) + + +assert invert_bit(12, 3) == 8 +assert invert_bit(18, 4) == 26 |
