advent-of-code/2018/day-01/02-recurring-freq.py

28 lines
365 B
Python
Raw Normal View History

2018-12-02 02:04:55 +01:00
#!/usr/bin/env python3
with open('input.txt', 'r') as f:
in_list = f.readlines()
in_list = [x.strip() for x in in_list]
in_list = [int(x) for x in in_list]
2018-12-02 14:07:18 +01:00
# print(in_list)
2018-12-02 02:04:55 +01:00
2018-12-02 14:07:18 +01:00
freq = set()
2018-12-02 02:04:55 +01:00
res = 0
i = 0
while True:
if i == len(in_list):
i = 0
res += in_list[i]
2018-12-02 14:07:18 +01:00
if res in freq:
2018-12-02 02:04:55 +01:00
break
2018-12-02 14:07:18 +01:00
freq.add(res)
2018-12-02 02:04:55 +01:00
i += 1
print(res)