aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/stuart-little/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-109/stuart-little/python')
-rwxr-xr-xchallenge-109/stuart-little/python/ch-1.py5
-rwxr-xr-xchallenge-109/stuart-little/python/ch-2.py21
2 files changed, 26 insertions, 0 deletions
diff --git a/challenge-109/stuart-little/python/ch-1.py b/challenge-109/stuart-little/python/ch-1.py
new file mode 100755
index 0000000000..d6ffa21cf1
--- /dev/null
+++ b/challenge-109/stuart-little/python/ch-1.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+
+# run <script>
+
+print("0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21")
diff --git a/challenge-109/stuart-little/python/ch-2.py b/challenge-109/stuart-little/python/ch-2.py
new file mode 100755
index 0000000000..c0dfbf495d
--- /dev/null
+++ b/challenge-109/stuart-little/python/ch-2.py
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+
+# run <script> <space-separated numbers>
+
+from itertools import permutations
+import string
+import sys
+
+def sumsEqNr(nr,ar,bl):
+ if (len(ar) <= 3):
+ return bl and (nr == sum(ar))
+ return sumsEqNr(nr,ar[2:],(bl and (nr == sum(ar[:3]))))
+
+def allSumsEq(ar):
+ return sumsEqNr(sum(ar[:2]),ar[1:],True)
+
+def pprnt(ar):
+ return "\nSolution: " + ", ".join([f"{c} = {v}" for (c,v) in list(zip(string.ascii_lowercase[:7],ar))]) + f"\nSum: {sum(ar[:2])}"
+
+sols = list(filter(allSumsEq,list(permutations(map(int, sys.argv[1:])))))
+print("No solution." if (not sols) else "\n".join(map(pprnt,sols)))