From de9bb292a37f04a96aed46d09cfcae2842c127fe Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Sun, 2 Dec 2018 14:07:18 +0100 Subject: [PATCH] Day 1: use set for faster lookup --- day-01/02-recurring-freq.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/day-01/02-recurring-freq.py b/day-01/02-recurring-freq.py index c0739e4..06771b5 100644 --- a/day-01/02-recurring-freq.py +++ b/day-01/02-recurring-freq.py @@ -7,9 +7,9 @@ with open('input.txt', 'r') as f: in_list = [x.strip() for x in in_list] in_list = [int(x) for x in in_list] -print(in_list) +# print(in_list) -freq = [] +freq = set() res = 0 i = 0 @@ -18,9 +18,10 @@ while True: i = 0 res += in_list[i] - freq.append(res) - if len(freq) != len(set(freq)): + if res in freq: break + + freq.add(res) i += 1 print(res)