Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- class Point:
- def __init__(self, x, y, vel_x, vel_y):
- self.x = x
- self.y = y
- self.vel_x = vel_x
- self.vel_y = vel_y
- def move(self):
- self.x += self.vel_x
- self.y += self.vel_y
- class Parser:
- def __init__(self, lines):
- self.lines = lines
- def get_points(self):
- res = []
- reg = re.compile('(-?[0-9]+)');
- for line in self.lines:
- vals = reg.findall(line.strip())
- res.append(Point(int(vals[0]), int(vals[1]), int(vals[2]), int(vals[3])))
- return res
- class Map:
- def __init__(self, points, width, height):
- self.points = points
- self.width = width
- self.height = height
- self.normalize()
- def normalize(self):
- min_x = min(map(lambda v: v.x, self.points))
- min_y = min(map(lambda v: v.y, self.points))
- for point in self.points:
- point.x -= min_x
- point.y -= min_y
- def move_points(self):
- for point in self.points:
- point.move()
- self.normalize()
- def print(self, observed_req = 0):
- observed_points = len(list(filter(lambda v: v.x <= self.width and v.y <= self.height, self.points)))
- if observed_points < observed_req:
- return False
- for i in range(self.height):
- print()
- for j in range(self.width):
- if any(filter(lambda v: v.x == j and v.y == i, self.points)):
- print('#', end='')
- else:
- print('.', end='')
- print()
- return True
- if __name__ == '__main__':
- with open('in.txt') as f:
- lines = f.readlines()
- my_map = Map(Parser(lines).get_points(), 200, 100)
- steps_count = 0
- while True:
- printed = my_map.print(observed_req = len(lines))
- my_map.move_points()
- steps_count += 1
- if printed:
- print('All points are visible: Steps {}'.format(steps_count))
- input()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement