DEV Community

loading...

Discussion on: Advent of Code 2020 Solution Megathread - Day 1: Report Repair

Collapse
r0f1 profile image
Florian Rohrer

I am also gonna be doing aoc this year. Here is my Python solution:

with open("input.txt") as f:
    l = [int(x.strip()) for x in f]

for i, n1 in enumerate(l):
    for j, n2 in enumerate(l[i+1:]):
        if n1 + n2 == 2020:
            part1 = n1 * n2
        for n3 in l[i+j+1:]:
            if n1 + n2 + n3 == 2020:
                part2 = n1 * n2 * n3

print(part1)
print(part2)
Enter fullscreen mode Exit fullscreen mode