|
| 1 | +data = open("E:\CodingStuff\AdventOfCode\Day11imput.txt") |
| 2 | +data = data.readlines() |
| 3 | +for row in range(len(data)): |
| 4 | + data[row] = data[row].strip("\n") |
| 5 | +data = [list(x) for x in data] |
| 6 | +data = [[int(c) for c in x] for x in data] |
| 7 | +print(len(data)) |
| 8 | +print(len(data[0])) |
| 9 | + |
| 10 | +class octgrid: |
| 11 | + def __init__(self, data): |
| 12 | + self.data=data |
| 13 | + self.count=0 |
| 14 | + |
| 15 | + def day(self): |
| 16 | + self.flashlist = [] |
| 17 | + for row in range(len(self.data)): |
| 18 | + for col in range(len(self.data[0])): |
| 19 | + self.data[row][col]+=1 |
| 20 | + |
| 21 | + for row in range(len(self.data)): |
| 22 | + for col in range(len(self.data[0])): |
| 23 | + if(self.data[row][col]>9 and (not ([row,col] in self.flashlist))): |
| 24 | + self.flash(row, col) |
| 25 | + for row in range(len(self.data)): |
| 26 | + for col in range(len(self.data[0])): |
| 27 | + if([row,col] in self.flashlist): |
| 28 | + self.data[row][col] = 0 |
| 29 | + return(len(self.flashlist)) |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + def flash(self, row, col): |
| 36 | + self.count+=1 |
| 37 | + self.flashlist.append([row,col]) |
| 38 | + for x in range(-1,2): |
| 39 | + for y in range(-1,2): |
| 40 | + file = row+x |
| 41 | + colunm = col+y |
| 42 | + if((file<len(self.data) and file>-1)): |
| 43 | + if((colunm<len(self.data[0]) and (colunm)>-1)): |
| 44 | + self.data[file][colunm]+=1 |
| 45 | + if((not ([file,colunm] in self.flashlist)) and self.data[file][colunm]>9): |
| 46 | + self.flash(file, colunm) |
| 47 | + |
| 48 | +grid = octgrid(data) |
| 49 | +b=0 |
| 50 | +for count in range(100): |
| 51 | + b+=grid.day() |
| 52 | +print(grid.count) |
| 53 | + |
| 54 | + |
0 commit comments