-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday1.py
executable file
·38 lines (30 loc) · 999 Bytes
/
day1.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
#!/usr/bin/env python3
# [Day 1: Report Repair](https://adventofcode.com/2020/day/1)
import sys
from pathlib import Path
filename = ("test.txt" if sys.argv[1] == "-t" else sys.argv[1]) if len(sys.argv) > 1 else "input.txt"
data = Path(filename).read_text().strip()
lines = list(map(int, data.splitlines()))
length = len(lines)
def part1():
for i in range(length):
for j in range(length):
if i != j:
if lines[i] + lines[j] == 2020:
print(lines[i] * lines[j])
return
def part2():
for i in range(length):
for j in range(length):
if i == j:
continue
p = lines[i] + lines[j]
if p > 2020:
continue
for k in range(length):
if i != j and i != k and j != k:
if p + lines[k] == 2020:
print(lines[i] * lines[j] * lines[k])
return
part1()
part2()