Last active
September 29, 2016 21:51
-
-
Save neoshrew/91f4968a5182430af20d138129168e60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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