aboutsummaryrefslogtreecommitdiff
path: root/challenge-120
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-120')
-rw-r--r--challenge-120/lubos-kolouch/python/ch-1.py28
-rw-r--r--challenge-120/lubos-kolouch/python/ch-2.py36
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-120/lubos-kolouch/python/ch-1.py b/challenge-120/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..9fb89c1f0f
--- /dev/null
+++ b/challenge-120/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,28 @@
+# ===============================================================================
+#
+# FILE: ch-2.pl
+#
+# USAGE: ./ch-2.pl
+#
+# DESCRIPTION: Perl Weekly Challenge #120
+# Task 1 - Swap Odd/Even bits
+#
+# AUTHOR: Lubos Kolouch
+# CREATED: 20210710 04:44:33 PM
+# ===============================================================================
+
+
+def swap_bits(what: int):
+
+ binary_what = str(bin(what)[2:])
+
+ if len(binary_what) % 2 == 1:
+ binary_what = "0" + binary_what
+
+ arr = [binary_what[i:i+2] for i in range(0, len(binary_what), 2)]
+ rev_arr = list(map(lambda x: x[::-1], arr))
+ return int("".join(rev_arr), 2)
+
+
+assert swap_bits(101) == 154
+assert swap_bits(18) == 33
diff --git a/challenge-120/lubos-kolouch/python/ch-2.py b/challenge-120/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..312f006329
--- /dev/null
+++ b/challenge-120/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,36 @@
+# ===============================================================================
+#
+# FILE: ch-2.py
+#
+# USAGE: ./ch-2.py
+#
+# DESCRIPTION: Perl Weekly Challenge #120
+# Task 2 - Clock Angle
+#
+# AUTHOR: Lubos Kolouch
+# CREATED: 20210710 04:44:33 PM
+# ===============================================================================
+
+
+def calc_angle(what: str):
+
+ hour, minute = map(int, what.split(':'))
+
+ # each minute is 6 degrees
+ angle_min = 6 * minute
+
+ # hour hand has moved 30 * whole hours + 0.5 * mins
+ angle_hour = 30 * hour + 0.5 * minute
+
+ result_angle = abs(angle_hour - angle_min)
+
+ # the challenge is asking for the smaller angle
+ if result_angle > 180:
+ return 360-result_angle
+
+ return result_angle
+
+
+assert calc_angle("03:10") == 35
+assert calc_angle("04:00") == 120
+assert calc_angle("10:14") == 137