-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathday_01b.py
More file actions
30 lines (26 loc) · 808 Bytes
/
day_01b.py
File metadata and controls
30 lines (26 loc) · 808 Bytes
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
#!/usr/bin/env python3
def main():
total = 2020
f = open("../input/day_01_input")
numbers = list()
for line in f:
line = line.strip().replace("\n", "").replace("\r", "")
numbers.append(int(line))
numbers.sort()
for start in range(0, len(numbers)):
mid = start + 1
end = len(numbers) - 1
while mid < end:
rem = total - numbers[start] - numbers[mid] - numbers[end]
if rem == 0:
print(numbers[start] * numbers[mid] * numbers[end])
return numbers[start] * numbers[mid] * numbers[end]
elif rem > 0:
mid += 1
elif rem < 0:
end -= 1
else:
print("WTH")
return 0
if __name__ == "__main__":
main()