day11p1 imp
This commit is contained in:
@@ -32,28 +32,18 @@ def nextSeat(x, y, grid):
|
||||
def nextRound(grid):
|
||||
next_grid = copy.deepcopy(grid)
|
||||
|
||||
count = 0
|
||||
difference = False
|
||||
|
||||
for x in range(0, width):
|
||||
for y in range(0, height):
|
||||
next_grid[x][y] = nextSeat(x, y, grid)
|
||||
|
||||
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] == '#':
|
||||
if next_grid[x][y] == '#':
|
||||
count += 1
|
||||
return count
|
||||
if next_grid[x][y] != grid[x][y]:
|
||||
difference = True
|
||||
|
||||
|
||||
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
|
||||
return next_grid, difference, count
|
||||
|
||||
|
||||
def part1():
|
||||
@@ -73,12 +63,11 @@ def part1():
|
||||
height = len(grid)
|
||||
|
||||
while True:
|
||||
grid, oldGrid = nextRound(grid)
|
||||
if equals(grid, oldGrid):
|
||||
seats = countSeats(grid)
|
||||
grid, difference, count = nextRound(grid)
|
||||
if not difference:
|
||||
break
|
||||
|
||||
print(f"Part 1: {seats}")
|
||||
print(f"Part 1: {count}")
|
||||
|
||||
|
||||
def part2():
|
||||
|
||||
Reference in New Issue
Block a user