day 11, 12 + folder refactoring
This commit is contained in:
parent
d9f6c01f2b
commit
06a5771fbf
78 changed files with 1242 additions and 8 deletions
67
11_day/code.py
Normal file
67
11_day/code.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
import pprint
|
||||
import fileinput
|
||||
|
||||
rows = []
|
||||
for line in fileinput.input():
|
||||
l = line.strip()
|
||||
if l == '':
|
||||
continue
|
||||
rows.append(list(map(int, list(l))))
|
||||
|
||||
pprint.pprint(rows)
|
||||
|
||||
def print_table(rows):
|
||||
for r in rows:
|
||||
print(''.join(map(str, r)))
|
||||
|
||||
def is_all_zeros(rows):
|
||||
return list(map(lambda r: ''.join(map(str, r)), rows)) == 10*[10*'0']
|
||||
|
||||
print_table(rows)
|
||||
|
||||
flashes = 0
|
||||
for step in range(10000):
|
||||
print(f'step #{step}')
|
||||
locked = []
|
||||
pops = 1
|
||||
while pops > 0:
|
||||
pops = 0
|
||||
for i in range(10):
|
||||
for j in range(10):
|
||||
if rows[i][j] >= 9:
|
||||
pops += 1
|
||||
flashes += 1
|
||||
diagonals = [
|
||||
(i-1, j-1),
|
||||
(i-1, j),
|
||||
(i-1, j+1),
|
||||
(i, j-1),
|
||||
(i, j+1),
|
||||
(i+1, j-1),
|
||||
(i+1, j),
|
||||
(i+1, j+1)
|
||||
]
|
||||
rows[i][j] = 0
|
||||
locked.append((i, j))
|
||||
for y,x in diagonals:
|
||||
if not (0 <= y < 10 and 0 <= x < 10): continue
|
||||
if (y, x) in locked: continue
|
||||
rows[y][x] += 1
|
||||
|
||||
for i in range(10):
|
||||
for j in range(10):
|
||||
if (i, j) in locked: continue
|
||||
rows[i][j] += 1
|
||||
|
||||
if is_all_zeros(rows):
|
||||
print(rows)
|
||||
print_table(rows)
|
||||
print(step+1)
|
||||
break
|
||||
|
||||
print_table(rows)
|
||||
|
||||
pprint.pprint(rows)
|
||||
print(flashes)
|
||||
|
||||
|
||||
5
11_day/example.txt
Normal file
5
11_day/example.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
11111
|
||||
19991
|
||||
19191
|
||||
19991
|
||||
11111
|
||||
10
11_day/example2.txt
Normal file
10
11_day/example2.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
5483143223
|
||||
2745854711
|
||||
5264556173
|
||||
6141336146
|
||||
6357385478
|
||||
4167524645
|
||||
2176841721
|
||||
6882881134
|
||||
4846848554
|
||||
5283751526
|
||||
11
11_day/input.txt
Normal file
11
11_day/input.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
4781623888
|
||||
1784156114
|
||||
3265645122
|
||||
4371551414
|
||||
3377154886
|
||||
7882314455
|
||||
6421348681
|
||||
7175424287
|
||||
5488242184
|
||||
2448568261
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue