-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1.py
39 lines (34 loc) · 1.03 KB
/
1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from pathlib import Path
import sys
def part1(input_file):
with open(input_file,"r") as f:
content = f.readlines()
freq = 0
for num in content:
freq += int(num)
return(freq)
def part2(input_file):
freq_list = []
with open(input_file,"r") as f:
content = f.readlines()
freq = 0
freq_list.append(freq)
while True:
for num in content:
freq += int(num)
# print(freq)
if freq in freq_list:
# print('Just repeated: ' + str(freq))
return freq
else:
freq_list.append(freq)
# print('Lenth of list is {}. Frequency is {}'.format(len(freq_list), freq))
return None
if __name__ == "__main__":
if len(sys.argv) > 1:
input_file = sys.argv[1]
else:
script_dir = Path(__file__).resolve().parent
input_file = script_dir / 'input1_1.txt'
print(part1(input_file))
print(part2(input_file))