Skip to content

Instantly share code, notes, and snippets.

@noel-yap
Last active August 26, 2020 15:02
Show Gist options
  • Save noel-yap/392c64ba29e645827c03dba97c43ac73 to your computer and use it in GitHub Desktop.
Save noel-yap/392c64ba29e645827c03dba97c43ac73 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
from typing import TextIO
try:
triangle: TextIO = open('triangle.txt')
tree = [[int(s) for s in line.split()]
for line in [line.rstrip() for line in triangle.readlines()]]
for r in range(len(tree) - 1, 0, -1):
for c in range(0, r):
if tree[r][c] > tree[r][c + 1]:
tree[r - 1][c] += tree[r][c]
else:
tree[r - 1][c] += tree[r][c + 1]
print(tree[0][0])
finally:
triangle.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment