aboutsummaryrefslogtreecommitdiff
path: root/challenge-146/laurent-rosenfeld/python
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-01-07 09:52:35 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-01-07 09:52:35 +0000
commit208b75a7c1919f3c2e3c3098fcb532d71cccfe63 (patch)
treeb3156f8cd3939c27b85bb171b0597b6c0dbdb168 /challenge-146/laurent-rosenfeld/python
parent1b2a5e704c4f5afc159c51872b1dcab1e5186698 (diff)
downloadperlweeklychallenge-club-208b75a7c1919f3c2e3c3098fcb532d71cccfe63.tar.gz
perlweeklychallenge-club-208b75a7c1919f3c2e3c3098fcb532d71cccfe63.tar.bz2
perlweeklychallenge-club-208b75a7c1919f3c2e3c3098fcb532d71cccfe63.zip
- Added solutions by Laurent Rosenfeld.
Diffstat (limited to 'challenge-146/laurent-rosenfeld/python')
-rw-r--r--challenge-146/laurent-rosenfeld/python/ch-2.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/challenge-146/laurent-rosenfeld/python/ch-2.py b/challenge-146/laurent-rosenfeld/python/ch-2.py
new file mode 100644
index 0000000000..7120a602a7
--- /dev/null
+++ b/challenge-146/laurent-rosenfeld/python/ch-2.py
@@ -0,0 +1,10 @@
+# for a node x/y less than 1, parent is x/(y-x)
+# for a node x/y larger than 1, parent is (x-y)/x
+
+def find_parent(num, denom):
+ return [num, denom - num] if num < denom else [num - denom, denom]
+
+for test in ([5, 2], [2, 5], [3, 4], [3, 5]):
+ parent = find_parent(test[0], test[1])
+ gd_parent = find_parent(parent[0], parent[1])
+ print("Node", test, "has parent", parent, "and grand-parent", gd_parent)