added day 11
This commit is contained in:
parent
f07db6262d
commit
b794684673
10
11/input01.txt
Normal file
10
11/input01.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
7777838353
|
||||||
|
2217272478
|
||||||
|
3355318645
|
||||||
|
2242618113
|
||||||
|
7182468666
|
||||||
|
5441641111
|
||||||
|
4773862364
|
||||||
|
5717125521
|
||||||
|
7542127721
|
||||||
|
4576678341
|
10
11/input01_sample.txt
Normal file
10
11/input01_sample.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
5483143223
|
||||||
|
2745854711
|
||||||
|
5264556173
|
||||||
|
6141336146
|
||||||
|
6357385478
|
||||||
|
4167524645
|
||||||
|
2176841721
|
||||||
|
6882881134
|
||||||
|
4846848554
|
||||||
|
5283751526
|
52
11/solve01.py
Normal file
52
11/solve01.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
def print_cavern(cavern):
|
||||||
|
for l in cavern:
|
||||||
|
print("".join([str(i) for i in l]))
|
||||||
|
|
||||||
|
def energy_simulate(cavern):
|
||||||
|
# increase energy level
|
||||||
|
for x in range(10):
|
||||||
|
for y in range(10):
|
||||||
|
cavern[y][x] += 1
|
||||||
|
|
||||||
|
# check flashes
|
||||||
|
flashed = []
|
||||||
|
while True:
|
||||||
|
flashed_round = 0
|
||||||
|
for x in range(10):
|
||||||
|
for y in range(10):
|
||||||
|
if cavern[y][x] < 10:
|
||||||
|
continue
|
||||||
|
if (x,y) in flashed:
|
||||||
|
continue
|
||||||
|
flashed_round += 1
|
||||||
|
flashed.append((x,y))
|
||||||
|
|
||||||
|
for d in ((0,1), (0,-1),(1,0),(-1,0), (1,1),(1,-1),(-1,1),(-1,-1)):
|
||||||
|
dx = x + d[0]
|
||||||
|
dy = y + d[1]
|
||||||
|
if (dx < 0) or (dy < 0):
|
||||||
|
continue
|
||||||
|
if (dx > 9) or (dy > 9):
|
||||||
|
continue
|
||||||
|
cavern[dy][dx] += 1
|
||||||
|
if flashed_round == 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# flashed set to 0
|
||||||
|
for d in flashed:
|
||||||
|
cavern[d[1]][d[0]] = 0
|
||||||
|
|
||||||
|
return len(flashed)
|
||||||
|
|
||||||
|
cavern = []
|
||||||
|
with open("input01.txt","r") as f:
|
||||||
|
for line in f:
|
||||||
|
cavern.append([int(x) for x in line.strip()])
|
||||||
|
|
||||||
|
flashes = 0
|
||||||
|
for i in range(100):
|
||||||
|
flashes += energy_simulate(cavern)
|
||||||
|
|
||||||
|
print(flashes)
|
55
11/solve02.py
Normal file
55
11/solve02.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
def print_cavern(cavern):
|
||||||
|
for l in cavern:
|
||||||
|
print("".join([str(i) for i in l]))
|
||||||
|
|
||||||
|
def energy_simulate(cavern):
|
||||||
|
# increase energy level
|
||||||
|
for x in range(10):
|
||||||
|
for y in range(10):
|
||||||
|
cavern[y][x] += 1
|
||||||
|
|
||||||
|
# check flashes
|
||||||
|
flashed = []
|
||||||
|
while True:
|
||||||
|
flashed_round = 0
|
||||||
|
for x in range(10):
|
||||||
|
for y in range(10):
|
||||||
|
if cavern[y][x] < 10:
|
||||||
|
continue
|
||||||
|
if (x,y) in flashed:
|
||||||
|
continue
|
||||||
|
flashed_round += 1
|
||||||
|
flashed.append((x,y))
|
||||||
|
|
||||||
|
for d in ((0,1), (0,-1),(1,0),(-1,0), (1,1),(1,-1),(-1,1),(-1,-1)):
|
||||||
|
dx = x + d[0]
|
||||||
|
dy = y + d[1]
|
||||||
|
if (dx < 0) or (dy < 0):
|
||||||
|
continue
|
||||||
|
if (dx > 9) or (dy > 9):
|
||||||
|
continue
|
||||||
|
cavern[dy][dx] += 1
|
||||||
|
if flashed_round == 0:
|
||||||
|
break
|
||||||
|
|
||||||
|
# flashed set to 0
|
||||||
|
for d in flashed:
|
||||||
|
cavern[d[1]][d[0]] = 0
|
||||||
|
|
||||||
|
return len(flashed)
|
||||||
|
|
||||||
|
cavern = []
|
||||||
|
with open("input01.txt","r") as f:
|
||||||
|
for line in f:
|
||||||
|
cavern.append([int(x) for x in line.strip()])
|
||||||
|
|
||||||
|
round = 0
|
||||||
|
while True:
|
||||||
|
round += 1
|
||||||
|
flashes = energy_simulate(cavern)
|
||||||
|
if flashes == 100:
|
||||||
|
break
|
||||||
|
|
||||||
|
print(round)
|
Loading…
x
Reference in New Issue
Block a user