daily pastebin goal
4%
SHARE
TWEET

Untitled

a guest Oct 20th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 611 def compact(grid, walls):
  2. 612     """
  3. 613     Converts a grid in the form of FTTTTFTTF to FTFFTFTTF, thus reducing the #
  4. 614     of pellets in the grid.
  5. 615     """
  6. 616     compact = grid.copy()
  7. 617
  8. 618     def cross(x, y):
  9. 619         xValues = [x - 1, x, x + 1]
  10. 620         yValues = [y - 1, y, y + 1]
  11. 621         numSurroundingPellets = 0
  12. 622         for xValue in xValues:
  13. 623             if xValue >= 0 and xValue < compact.width:
  14. 624                 for yValue in yValues:
  15. 625                     if yValue >= 0 and yValue < compact.height:
  16. 626                         if not compact[xValue, yValue] and not walls[xValue, yValue]:
  17. 627                             return True
  18. 628                         elif compact[xValue, yValue]:
  19. 629                             numSurroundingPellets += 1
  20. 630         return numSurroundingPellets == 8
  21. 631        
  22. 632     for i in range(compact.width):
  23. 633         for j in range(compact.height):
  24. 634             if compact[i][j]:
  25. 635                 compact[i][j] = cross(i, j)
  26. 636                
  27. 637     return compact
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top