aboutsummaryrefslogtreecommitdiff
path: root/challenge-160/lubos-kolouch/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-160/lubos-kolouch/python')
-rw-r--r--challenge-160/lubos-kolouch/python/ch-1.py27
-rw-r--r--challenge-160/lubos-kolouch/python/ch-2.py20
2 files changed, 47 insertions, 0 deletions
diff --git a/challenge-160/lubos-kolouch/python/ch-1.py b/challenge-160/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..9103fe6c84
--- /dev/null
+++ b/challenge-160/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,27 @@
+""" Challenge 160 Task 1"""
+
+from num2words import num2words
+
+
+def four_magic(what: int) -> str:
+ """Do the conversion magic"""
+
+ output = []
+
+ while 1:
+ new_num = len(num2words(what))
+
+ if what == 4:
+ output.append(num2words(what) + " is magic.")
+ break
+ output.append(num2words(what) + " is " + num2words(new_num))
+ what = new_num
+
+ out_str = ", ".join(output)
+
+ return out_str.capitalize()
+
+
+assert four_magic(5) == "Five is four, four is magic."
+assert four_magic(7) == "Seven is five, five is four, four is magic."
+assert four_magic(6) == "Six is three, three is five, five is four, four is magic."
diff --git a/challenge-160/lubos-kolouch/python/ch-2.py b/challenge-160/lubos-kolouch/python/ch-2.py
new file mode 100644
index 0000000000..dd95012303
--- /dev/null
+++ b/challenge-160/lubos-kolouch/python/ch-2.py
@@ -0,0 +1,20 @@
+""" Challenge 160 Task 2 """
+
+
+def get_eq_index(what: list) -> int:
+ """Get the Equilibrium Index"""
+
+ elem_count = len(what)
+
+ for i in range(1, elem_count - 1):
+ if sum(what[0:i]) == sum(what[i + 1 : elem_count]):
+ return i
+
+ return -1
+
+
+assert get_eq_index([1, 3, 5, 7, 9]) == 3
+assert get_eq_index([1, 2, 3, 4, 5]) == -1
+assert get_eq_index([2, 4, 2]) == 1
+
+assert get_eq_index([2]) == -1