Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 611 def compact(grid, walls):
- 612 """
- 613 Converts a grid in the form of FTTTTFTTF to FTFFTFTTF, thus reducing the #
- 614 of pellets in the grid.
- 615 """
- 616 compact = grid.copy()
- 617
- 618 def cross(x, y):
- 619 xValues = [x - 1, x, x + 1]
- 620 yValues = [y - 1, y, y + 1]
- 621 numSurroundingPellets = 0
- 622 for xValue in xValues:
- 623 if xValue >= 0 and xValue < compact.width:
- 624 for yValue in yValues:
- 625 if yValue >= 0 and yValue < compact.height:
- 626 if not compact[xValue, yValue] and not walls[xValue, yValue]:
- 627 return True
- 628 elif compact[xValue, yValue]:
- 629 numSurroundingPellets += 1
- 630 return numSurroundingPellets == 8
- 631
- 632 for i in range(compact.width):
- 633 for j in range(compact.height):
- 634 if compact[i][j]:
- 635 compact[i][j] = cross(i, j)
- 636
- 637 return compact
Add Comment
Please, Sign In to add comment