Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. class VPoint:
  5.  
  6. def __init__(self, x, y, vx, vy):
  7. self.x = x
  8. self.y = y
  9. self.vx = vx
  10. self.vy = vy
  11. self.flag1 = False
  12.  
  13. @staticmethod
  14. def parse_str(line):
  15. m = re.findall("-?\d+", line)
  16. vp = VPoint(int(m[0]),
  17. int(m[1]),
  18. int(m[2]),
  19. int(m[3]))
  20.  
  21. return vp
  22.  
  23. def move(self):
  24. self.x += self.vx
  25. self.y += self.vy
  26.  
  27. def is_neighbour(self, vpoint):
  28. return (self.x == vpoint.x and self.y == vpoint.y - 1) \
  29. or (self.x == vpoint.x and self.y == vpoint.y + 1) \
  30. or (self.x == vpoint.x - 1 and self.y == vpoint.y - 1) \
  31. or (self.x == vpoint.x - 1 and self.y == vpoint.y) \
  32. or (self.x == vpoint.x - 1 and self.y == vpoint.y + 1) \
  33. or (self.x == vpoint.x + 1 and self.y == vpoint.y - 1) \
  34. or (self.x == vpoint.x + 1 and self.y == vpoint.y) \
  35. or (self.x == vpoint.x + 1 and self.y == vpoint.y + 1)
  36.  
  37.  
  38. def depth_search(vpoint, grid):
  39. count = 0
  40. if vpoint.flag1 == True:
  41. return 0
  42.  
  43. vpoint.flag1 = True
  44. for vp in grid:
  45. if vpoint.is_neighbour(vp):
  46. count += depth_search(vp, grid)
  47. return count + 1
  48.  
  49.  
  50. def get_non_flagged(grid):
  51. for vp in grid:
  52. if not vp.flag1:
  53. return vp
  54. return None
  55.  
  56. def unflag(grid):
  57. for vp in grid:
  58. vp.flag1 = False
  59.  
  60. def print_grid(grid, vp, size):
  61. ggg = [ ["." for _ in range(size)] for _ in range(size)]
  62. print("Hello")
  63.  
  64. def move_all(grid):
  65. for vp in grid:
  66. vp.move()
  67.  
  68. def main():
  69. with open("data.txt") as f:
  70. lines = f.readlines()
  71.  
  72. points = []
  73. for line in lines:
  74. points.append(VPoint.parse_str(line))
  75.  
  76. while True:
  77. unflag(points)
  78. while True:
  79. ufVPoint = get_non_flagged(points)
  80. if ufVPoint is None:
  81. move_all(points)
  82. break
  83.  
  84. if depth_search(ufVPoint, points) > 5:
  85. print_grid(points, ufVPoint, 20)
  86.  
  87.  
  88.  
  89. if __name__ == "__main__":
  90. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement