From 408ceff1489f4e820d2dcccf143fcb0cf05954a2 Mon Sep 17 00:00:00 2001 From: Sebastian Seedorf Date: Wed, 2 Dec 2020 09:11:29 +0100 Subject: [PATCH] Day 1 (part 1 linear runtime) --- day01/part1.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/day01/part1.py b/day01/part1.py index 555d749..3552af5 100644 --- a/day01/part1.py +++ b/day01/part1.py @@ -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)