-
Notifications
You must be signed in to change notification settings - Fork 0
/
day3.py
81 lines (63 loc) · 1.96 KB
/
day3.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
def cleanLine(line):
newLine = []
lineArr = line.split()
ID = int(lineArr[0].replace("#", ""))
left = int(lineArr[2].split(",")[0])
right = int(lineArr[2].split(",")[1].replace(":", ""))
newLine.append(left)
newLine.append(right)
width = int(lineArr[3].split("x")[0])
height = int(lineArr[3].split("x")[1])
newLine.append(width)
newLine.append(height)
newLine.append(ID)
return newLine
def makeArr(x, y):
arr = []
for i in range(0, x):
secondArr = []
for j in range(0, y):
secondArr.append(0)
arr.append(secondArr)
return arr
def part1(inputData = "input/input3.txt"):
arr = makeArr(1000, 1000)
lines = 0
with open(inputData) as f:
lines = f.readlines()
for line in lines:
line = cleanLine(line)
for i in range(line[0], line[0] + line[2]):
for j in range(line[1], line[1] + line[3]):
arr[i][j] += 1
count = 0
for i in range(0, 1000):
for j in range(0, 1000):
if arr[i][j] > 1:
count += 1
print("day 3, part 1: " + str(count))
return arr
def part2(inputData = "input/input3.txt", arr = 0):
with open(inputData) as f:
lines = f.readlines()
if arr == 0:
arr = makeArr(1000, 1000)
for line in lines:
line = cleanLine(line)
for i in range(line[0], line[0] + line[2]):
for j in range(line[1], line[1] + line[3]):
arr[i][j] += 1
for line in lines:
line = cleanLine(line)
okay = True
for i in range(line[0], line[0] + line[2]):
for j in range(line[1], line[1] + line[3]):
if arr[i][j] > 1:
okay = False
if okay == True:
print("day 3, part 2: " + str(line[4]))
def main(inputData = "input/input3.txt"):
arr = part1(inputData)
part2(inputData, arr)
if __name__ == "__main__":
main()