Day 1 (part 1 linear runtime)
This commit is contained in:
@@ -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 = []
|
done = set()
|
||||||
highs = []
|
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
if item < 1010:
|
counterpart = 2020 - item
|
||||||
lows.append(item)
|
if counterpart in done:
|
||||||
else:
|
print("Found {} and {}: Sum={} Product={}".format(item, counterpart, item+counterpart, item*counterpart))
|
||||||
highs.append(item)
|
break
|
||||||
|
done.add(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))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user