-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay11.py
More file actions
101 lines (99 loc) · 3.57 KB
/
Day11.py
File metadata and controls
101 lines (99 loc) · 3.57 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import numpy as np
def Octopuslight(steps):
f = open("input day 11.txt", "r")
lines = f.readlines()
numbergrid = []
for line in lines:
numberrow = []
if line[-1] == '\n':
line = line[:-1]
for number in line:
numberrow.append(int(number))
numbergrid.append(numberrow)
numbergrid = np.asarray(numbergrid)
step = 0
print(numbergrid)
totalflashes = 0
while step < steps:
numbergrid += 1
flashed = np.zeros((10, 10), dtype=int)
while np.amax(numbergrid) > 9:
for x in range(10):
for y in range(10):
if numbergrid[x, y] > 9 and flashed[x, y] == 0:
totalflashes += 1
flashed[x, y] = 1
numbergrid[x, y] = 0
if x > 0 and y > 0:
numbergrid[x - 1, y - 1] += 1
if y > 0:
numbergrid[x, y - 1] += 1
if x < 9 and y > 0:
numbergrid[x + 1, y - 1] += 1
if x > 0:
numbergrid[x - 1, y] += 1
if x < 9:
numbergrid[x + 1, y] += 1
if x > 0 and y < 9:
numbergrid[x - 1, y + 1] += 1
if y < 9:
numbergrid[x, y + 1] += 1
if x < 9 and y < 9:
numbergrid[x + 1, y + 1] += 1
for x in range(10):
for y in range(10):
if flashed[x, y] == 1:
numbergrid[x, y] = 0
print(numbergrid)
step += 1
print(totalflashes)
def Octopuslight_sync():
f = open("input day 11.txt", "r")
lines = f.readlines()
numbergrid = []
for line in lines:
numberrow = []
if line[-1] == '\n':
line = line[:-1]
for number in line:
numberrow.append(int(number))
numbergrid.append(numberrow)
numbergrid = np.asarray(numbergrid)
step = 0
print(numbergrid)
totalflashes = 0
while True:
numbergrid += 1
flashed = np.zeros((10, 10), dtype=int)
while np.amax(numbergrid) > 9:
for x in range(10):
for y in range(10):
if numbergrid[x, y] > 9 and flashed[x, y] == 0:
totalflashes += 1
flashed[x, y] = 1
numbergrid[x, y] = 0
if x > 0 and y > 0:
numbergrid[x - 1, y - 1] += 1
if y > 0:
numbergrid[x, y - 1] += 1
if x < 9 and y > 0:
numbergrid[x + 1, y - 1] += 1
if x > 0:
numbergrid[x - 1, y] += 1
if x < 9:
numbergrid[x + 1, y] += 1
if x > 0 and y < 9:
numbergrid[x - 1, y + 1] += 1
if y < 9:
numbergrid[x, y + 1] += 1
if x < 9 and y < 9:
numbergrid[x + 1, y + 1] += 1
if np.array_equiv(flashed, np.ones((10, 10))):
print(step + 1)
break
for x in range(10):
for y in range(10):
if flashed[x, y] == 1:
numbergrid[x, y] = 0
print(numbergrid)
step += 1