Skip to content

Instantly share code, notes, and snippets.

@joostrijneveld
Created October 21, 2014 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joostrijneveld/bafb12b807472e60deb1 to your computer and use it in GitHub Desktop.
Save joostrijneveld/bafb12b807472e60deb1 to your computer and use it in GitHub Desktop.
This file contains the solution to Problem 67 of Project Euler
#! /usr/bin/env python
with open('p067_triangle.txt') as f:
triangle = [[int(y) for y in x.strip().split(' ')] for x in f.readlines()]
upsidedown = list(reversed(triangle))
rowpairs = zip(upsidedown, upsidedown[1:])
for bot, top in rowpairs:
for i, x in enumerate(top):
top[i] = x + max(bot[i], bot[i+1])
print(triangle[0][0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment