day11p1 imp

This commit is contained in:
2020-12-12 13:12:03 +01:00
parent d858de5d4a
commit 41155ac168

View File

@@ -32,28 +32,18 @@ def nextSeat(x, y, grid):
def nextRound(grid): def nextRound(grid):
next_grid = copy.deepcopy(grid) next_grid = copy.deepcopy(grid)
count = 0
difference = False
for x in range(0, width): for x in range(0, width):
for y in range(0, height): for y in range(0, height):
next_grid[x][y] = nextSeat(x, y, grid) next_grid[x][y] = nextSeat(x, y, grid)
if next_grid[x][y] == '#':
return next_grid, grid
def countSeats(grid1):
count = 0
for x in range(0, width):
for y in range(0, height):
if grid1[x][y] == '#':
count += 1 count += 1
return count if next_grid[x][y] != grid[x][y]:
difference = True
return next_grid, difference, count
def equals(grid1, grid2):
for x in range(0, width):
for y in range(0, height):
if grid1[x][y] != grid2[x][y]:
return False
return True
def part1(): def part1():
@@ -73,12 +63,11 @@ def part1():
height = len(grid) height = len(grid)
while True: while True:
grid, oldGrid = nextRound(grid) grid, difference, count = nextRound(grid)
if equals(grid, oldGrid): if not difference:
seats = countSeats(grid)
break break
print(f"Part 1: {seats}") print(f"Part 1: {count}")
def part2(): def part2():