-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday11_pretty.py
62 lines (50 loc) · 1.55 KB
/
day11_pretty.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
import numpy
input = []
with open("day11_input.txt") as file:
input = [list(map(lambda x: int(x), line.strip()))
for line in file.readlines()]
octoMap = numpy.pad(numpy.asmatrix(input), 1,
"constant", constant_values=(9, 9))
yMax = octoMap.shape[0]
xMax = octoMap.shape[1]
c = 0
i = -1
while True:
i += 1
if i == 100:
print(c)
freshMap = numpy.ones((yMax, xMax), dtype=bool)
for y in range(1, yMax-1):
for x in range(1, xMax-1):
octoMap[y, x] += 1
while True:
flashHappened = False
for y in range(1, yMax-1):
for x in range(1, xMax-1):
if octoMap[y, x] > 9 and freshMap[y, x]:
c += 1
flashHappened = True
freshMap[y, x] = False
octoMap[y, x] = 0
octoMap[y-1, x-1] += 1
octoMap[y-1, x] += 1
octoMap[y-1, x+1] += 1
octoMap[y, x-1] += 1
octoMap[y, x+1] += 1
octoMap[y+1, x-1] += 1
octoMap[y+1, x] += 1
octoMap[y+1, x+1] += 1
if not flashHappened:
break
for y in range(1, yMax-1):
for x in range(1, xMax-1):
if freshMap[y, x] == False:
octoMap[y, x] = 0
isFin = True
for y in range(1, yMax-1):
for x in range(1, xMax-1):
if freshMap[y, x] == True:
isFin = False
if isFin:
print(i+1)
break