Created
April 13, 2022 07:39
-
-
Save eliaperantoni/cbae45fbafa4c9866a78878505f829bc 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 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