Day 1: use set for faster lookup

master
Alfred Melch 6 years ago
parent 2f3b1401f7
commit de9bb292a3

@ -7,9 +7,9 @@ with open('input.txt', 'r') as f:
in_list = [x.strip() for x in in_list] in_list = [x.strip() for x in in_list]
in_list = [int(x) 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 res = 0
i = 0 i = 0
@ -18,9 +18,10 @@ while True:
i = 0 i = 0
res += in_list[i] res += in_list[i]
freq.append(res) if res in freq:
if len(freq) != len(set(freq)):
break break
freq.add(res)
i += 1 i += 1
print(res) print(res)

Loading…
Cancel
Save