blob: b237f83d167d695e49d46fd10f3cf6fc5402d875 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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])
|