Evoid-null

Advent of code 2021 day 11 part 1&2

Dec 11th, 2021 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. e = [[0]*12] + [list(map(int,list('0'+i.replace("\n","")+'0'))) for i in open('input11.txt').read().split("\n")] + [[0]*12]
  2. flashdb,steps,simflash = 0,0,0
  3. while(simflash < 100):
  4.     flashed = True
  5.     simflash=0
  6.     while (flashed):
  7.         flashed = False
  8.         for i in range(1,11):
  9.             for j in range(1,11):
  10.                 if (e[i][j] > 9):
  11.                     e[i][j] = 0
  12.                     for k in [[1,0],[1,1],[1,-1],[-1,0],[-1,+1],[-1,-1],[0,1],[0,-1]]:
  13.                         if e[i+k[0]][j+k[1]] != 0:
  14.                             e[i+k[0]][j+k[1]]+=1
  15.                     simflash+=1
  16.                     flashed = True
  17.     if steps == 101: print('part 1:',flashdb)
  18.     flashdb+=simflash
  19.     e = [[a+1 for a in b] for b in e]
  20.     steps+=1
  21. print('part 2:',steps-1)
  22.  
Add Comment
Please, Sign In to add comment