aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/abigail/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-109/abigail/python')
-rw-r--r--challenge-109/abigail/python/ch-1.py39
-rw-r--r--challenge-109/abigail/python/ch-2.py66
2 files changed, 105 insertions, 0 deletions
diff --git a/challenge-109/abigail/python/ch-1.py b/challenge-109/abigail/python/ch-1.py
new file mode 100644
index 0000000000..f9e51a0897
--- /dev/null
+++ b/challenge-109/abigail/python/ch-1.py
@@ -0,0 +1,39 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-1.py [plain | compute]
+#
+
+import sys
+
+COUNT = 20
+PLAIN = 0
+COMPUTE = 1
+
+def divisor_sum (n):
+ sum = 0
+ for i in range (2, n / 2 + 1):
+ if n % i == 0:
+ sum = sum + i
+ return (sum)
+
+type = PLAIN
+
+if len (sys . argv) > 1 and sys . argv [1] == "compute":
+ type = COMPUTE
+
+
+if type == PLAIN:
+ print ("0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21")
+
+
+if type == COMPUTE:
+ for n in range (1, COUNT + 1):
+ if n > 1:
+ print (", ", end = '')
+ print (divisor_sum (n), end = '')
+ print ("")
diff --git a/challenge-109/abigail/python/ch-2.py b/challenge-109/abigail/python/ch-2.py
new file mode 100644
index 0000000000..c17ac94211
--- /dev/null
+++ b/challenge-109/abigail/python/ch-2.py
@@ -0,0 +1,66 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as: python ch-2.py < input-file
+#
+
+import fileinput
+
+SIZE = 7
+
+fmt = "{:d} {:d} {:d} {:d} {:d} {:d} {:d}"
+
+#
+# Brute forcing all possiblities, with an early return
+#
+for line in fileinput . input ():
+ numbers = list (map (lambda x: int (x), line . split ()))
+
+ for a_i in range (0, SIZE):
+ for b_i in range (0, SIZE):
+ if a_i == b_i:
+ continue
+ target = numbers [a_i] + numbers [b_i]
+
+ for c_i in range (0, SIZE):
+ if c_i == a_i or c_i == b_i:
+ continue
+
+ for d_i in range (0, SIZE):
+ if d_i == a_i or d_i == b_i or d_i == c_i:
+ continue
+
+ if target != numbers [b_i] + numbers [c_i] + numbers [d_i]:
+ continue
+
+ for e_i in range (0, SIZE):
+ if e_i == a_i or e_i == b_i or e_i == c_i or \
+ e_i == d_i:
+ continue
+
+ for f_i in range (0, SIZE):
+ if f_i == a_i or f_i == b_i or f_i == c_i or \
+ f_i == d_i or f_i == e_i:
+ continue
+ if target != numbers [d_i] + numbers [e_i] + \
+ numbers [f_i]:
+ continue
+
+ for g_i in range (0, SIZE):
+ if g_i == a_i or g_i == b_i or g_i == c_i or \
+ g_i == d_i or g_i == e_i or g_i == f_i:
+ continue
+ if target != numbers [f_i] + numbers [g_i]:
+ continue
+
+ print (fmt . format (numbers [a_i],
+ numbers [b_i],
+ numbers [c_i],
+ numbers [d_i],
+ numbers [e_i],
+ numbers [f_i],
+ numbers [g_i]))