Skip to content

Instantly share code, notes, and snippets.

@neoshrew
Last active September 29, 2016 21:51
Show Gist options
  • Save neoshrew/91f4968a5182430af20d138129168e60 to your computer and use it in GitHub Desktop.
Save neoshrew/91f4968a5182430af20d138129168e60 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import sys
if sys.version_info.major >2:
xrange = range
last = []
with open("numbers", "r") as fandle:
for line in fandle:
current = [int(num_str) for num_str in line.split(' ')]
current_len = len(current)
if current_len == 1:
last = current
continue
for i in xrange(current_len):
if i == 0:
current[i] += last[0]
elif i == current_len - 1:
current[i] += last[-1]
else:
current[i] += max(last[i-1:i+1])
last = current
print(max(last))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment