aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/abigail/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-100/abigail/python/ch-2.py')
-rw-r--r--challenge-100/abigail/python/ch-2.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-100/abigail/python/ch-2.py b/challenge-100/abigail/python/ch-2.py
new file mode 100644
index 0000000000..b237f83d16
--- /dev/null
+++ b/challenge-100/abigail/python/ch-2.py
@@ -0,0 +1,36 @@
+#!/opt/local/bin/python
+
+#
+# See ../README.md
+#
+
+#
+# Run as python ch-2.py < input-file
+#
+
+import fileinput
+import re
+
+numbers = []
+
+#
+# Read in the data
+#
+for line in fileinput . input ():
+ numbers . append (list (map (lambda x: int (x),
+ re . compile (r'\s+')
+ . split (line . strip ()))))
+
+
+#
+# Calculate the minimum path, bottom to top
+#
+for x in range (len (numbers) - 2, -1, -1):
+ for y in range (0, len (numbers [x])):
+ numbers [x] [y] = numbers [x] [y] + min (numbers [x + 1] [y],
+ numbers [x + 1] [y + 1])
+
+#
+# Print result
+#
+print (numbers [0] [0])