Day 1 (part 1 linear runtime)

This commit is contained in:
Sebastian Seedorf
2020-12-02 09:11:29 +01:00
parent 573ac58519
commit 408ceff148

View File

@@ -1,18 +1,10 @@
items = [int(x.strip()) for x in open("input.txt")]
items = (int(x.strip()) for x in open("input.txt"))
lows = []
highs = []
done = set()
for item in items:
if item < 1010:
lows.append(item)
else:
highs.append(item)
print(lows)
print(highs)
for low in lows:
for high in highs:
if low + high == 2020:
print("Found {} and {}: Sum={} Product={}".format(low, high, low+high, low*high))
counterpart = 2020 - item
if counterpart in done:
print("Found {} and {}: Sum={} Product={}".format(item, counterpart, item+counterpart, item*counterpart))
break
done.add(item)