aboutsummaryrefslogtreecommitdiff
path: root/challenge-121/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-121/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-121/lubos-kolouch/python/ch-1.py20
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