-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.py
57 lines (42 loc) · 1.17 KB
/
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
path = "./Inputs/day1.txt"
# path = "./Inputs/day1Test.txt";
def part1():
file = open(path, "r")
lines = file.readlines()
i = j = 0
found = False
while i < len(lines) and not found:
num1 = int(lines[i])
while j < len(lines) and not found:
num2 = int(lines[j])
if num1 + num2 == 2020:
print("Part 1:")
print(num1*num2)
found = True
j += 1
i += 1
j = 0
file.close()
def part2():
file = open(path, "r")
lines = file.readlines()
i = j = k = 0
found = False
while i < len(lines) and not found:
num1 = int(lines[i])
while j < len(lines) and not found:
num2 = int(lines[j])
while k < len(lines) and not found:
num3 = int(lines[k])
if num1 + num2 + num3 == 2020:
print("Part 2:")
print(num1*num2*num3)
found = True
k += 1
j += 1
k = 0
i += 1
j = 0
file.close()
part1()
part2()