Skip to content

Instantly share code, notes, and snippets.

@eliaperantoni
Created April 13, 2022 07:39
Show Gist options
  • Save eliaperantoni/cbae45fbafa4c9866a78878505f829bc to your computer and use it in GitHub Desktop.
Save eliaperantoni/cbae45fbafa4c9866a78878505f829bc to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
with open("input.txt") as f:
f.readline()
t = [[int(word) for word in line.split(" ")] for line in f.readlines() if len(line) > 0]
def solve(x, y):
if x == len(t) - 1:
return t[x][y]
return t[x][y] + max(solve(x + 1, y), solve(x + 1, y + 1))
sol = solve(0, 0)
with open("output.txt", "w") as f:
f.write(str(sol) + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment