add second part of solution 1

This commit is contained in:
randomuser 2021-07-20 12:53:28 -05:00
parent 458e998c3d
commit 64388e3881
2 changed files with 24 additions and 7 deletions

6
2020/1/sample_input Normal file
View File

@ -0,0 +1,6 @@
1721
979
366
299
675
1456

View File

@ -2,12 +2,23 @@
fd = open("input", "r") fd = open("input", "r")
lines = fd.readlines() lines = fd.readlines()
lines = [i.rstrip() for i in lines]
mustbreak = False mustbreak = False
for i in lines: def part1():
for j in lines: for i in lines:
if int(i) + int(j) == 2020: for j in lines:
print("{} * {} == {}".format(int(i), int(j), int(i) * int(j))) if int(i) + int(j) == 2020:
mustbreak = True print("{} * {} = {}".format(int(i), int(j), int(i) * int(j)))
break return
if mustbreak: break
def part2():
for i in lines:
for j in lines:
for k in lines:
if int(i) + int(j) + int(k) == 2020:
print("{} * {} * {} = {}".format(int(i), int(j), int(k), int(i) * int(j) * int(k)))
return
part1()
part2()