Skip to content

Commit cee9290

Browse files
authored
better solution
1 parent 269b0b4 commit cee9290

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

Day 11.py

+23-32
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
def done(inp):
1717
for y in range(1,len(inp)-1):
1818
for x in range(1,len(inp[y])-1):
19-
if inp[y][x] > 9 and inp[y][x] < 100:
19+
if inp[y][x] > 9:
2020
return False
2121
return True
2222

@@ -37,22 +37,17 @@ def part1(inp):
3737
while not done(inp):
3838
for y in range(1,len(inp)-1):
3939
for x in range(1,len(inp[y])-1):
40-
if inp[y][x] > 9 and inp[y][x] < 100:
41-
inp[y][x] = 100
42-
if inp[y+1][x+1] >= 0: inp[y+1][x+1] += 1
43-
if inp[y-1][x-1] >= 0: inp[y-1][x-1] += 1
44-
if inp[y+1][x-1] >= 0: inp[y+1][x-1] += 1
45-
if inp[y-1][x+1] >= 0: inp[y-1][x+1] += 1
46-
if inp[y+1][x] >= 0: inp[y+1][x] += 1
47-
if inp[y-1][x] >= 0: inp[y-1][x] += 1
48-
if inp[y][x+1] >= 0: inp[y][x+1] += 1
49-
if inp[y][x-1] >= 0: inp[y][x-1] += 1
50-
51-
for y in range(1,len(inp)-1):
52-
for x in range(1,len(inp[y])-1):
53-
if inp[y][x] >= 100:
54-
inp[y][x] = 0
55-
flashes += 1
40+
if inp[y][x] > 9:
41+
inp[y][x] = 0
42+
flashes += 1
43+
if inp[y+1][x+1] > 0: inp[y+1][x+1] += 1
44+
if inp[y-1][x-1] > 0: inp[y-1][x-1] += 1
45+
if inp[y+1][x-1] > 0: inp[y+1][x-1] += 1
46+
if inp[y-1][x+1] > 0: inp[y-1][x+1] += 1
47+
if inp[y+1][x] > 0: inp[y+1][x] += 1
48+
if inp[y-1][x] > 0: inp[y-1][x] += 1
49+
if inp[y][x+1] > 0: inp[y][x+1] += 1
50+
if inp[y][x-1] > 0: inp[y][x-1] += 1
5651
print(flashes)
5752

5853
def part2(inp):
@@ -66,22 +61,18 @@ def part2(inp):
6661
while not done(inp):
6762
for y in range(1,len(inp)-1):
6863
for x in range(1,len(inp[y])-1):
69-
if inp[y][x] > 9 and inp[y][x] < 100:
70-
inp[y][x] = 100
71-
if inp[y+1][x+1] >= 0: inp[y+1][x+1] += 1
72-
if inp[y-1][x-1] >= 0: inp[y-1][x-1] += 1
73-
if inp[y+1][x-1] >= 0: inp[y+1][x-1] += 1
74-
if inp[y-1][x+1] >= 0: inp[y-1][x+1] += 1
75-
if inp[y+1][x] >= 0: inp[y+1][x] += 1
76-
if inp[y-1][x] >= 0: inp[y-1][x] += 1
77-
if inp[y][x+1] >= 0: inp[y][x+1] += 1
78-
if inp[y][x-1] >= 0: inp[y][x-1] += 1
64+
if inp[y][x] > 9:
65+
inp[y][x] = 0
66+
flashes += 1
67+
if inp[y+1][x+1] > 0: inp[y+1][x+1] += 1
68+
if inp[y-1][x-1] > 0: inp[y-1][x-1] += 1
69+
if inp[y+1][x-1] > 0: inp[y+1][x-1] += 1
70+
if inp[y-1][x+1] > 0: inp[y-1][x+1] += 1
71+
if inp[y+1][x] > 0: inp[y+1][x] += 1
72+
if inp[y-1][x] > 0: inp[y-1][x] += 1
73+
if inp[y][x+1] > 0: inp[y][x+1] += 1
74+
if inp[y][x-1] > 0: inp[y][x-1] += 1
7975

80-
for y in range(1,len(inp)-1):
81-
for x in range(1,len(inp[y])-1):
82-
if inp[y][x] >= 100:
83-
inp[y][x] = 0
84-
flashes += 1
8576
if flashes == 100:
8677
break
8778
print(step)

0 commit comments

Comments
 (0)