-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheuler18.py~
More file actions
25 lines (23 loc) · 756 Bytes
/
euler18.py~
File metadata and controls
25 lines (23 loc) · 756 Bytes
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
import json
def main():
with open('euler18tri', 'r') as f:
mxtot = -1
last = -1
for line in f:
next = line[:-1].split(' ')
if last == -1:
last = next
else:
for i in xrange(len(next)):
if i == 0:
next[i] = int(next[i]) + int(last[i])
elif i == len(last):
next[i] = int(next[i]) + int(last[-1])
else:
next[i] = int(next[i]) + int(max(last[i - 1], last[i]))
mxtot = max(next)
print next
print " "
last = next
print "Max is " + str(mxtot)
main()