• API
• FAQ
• Tools
• Archive
SHARE
TWEET # AOC-10 a guest Dec 10th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import re
2.
3. class Point:
4.
5.     def __init__(self, x, y, vel_x, vel_y):
6.         self.x = x
7.         self.y = y
8.         self.vel_x = vel_x
9.         self.vel_y = vel_y
10.
11.     def move(self):
12.         self.x += self.vel_x
13.         self.y += self.vel_y
14.
15. class Parser:
16.
17.     def __init__(self, lines):
18.         self.lines = lines
19.
20.     def get_points(self):
21.         res = []
22.         reg = re.compile('(-?[0-9]+)');
23.         for line in self.lines:
24.             vals = reg.findall(line.strip())
25.             res.append(Point(int(vals), int(vals), int(vals), int(vals)))
26.         return res
27.
28. class Map:
29.
30.     def __init__(self, points, width, height):
31.         self.points = points
32.         self.width = width
33.         self.height = height
34.         self.normalize()
35.
36.     def normalize(self):
37.         min_x = min(map(lambda v: v.x, self.points))
38.         min_y = min(map(lambda v: v.y, self.points))
39.         for point in self.points:
40.             point.x -= min_x
41.             point.y -= min_y
42.
43.     def move_points(self):
44.         for point in self.points:
45.             point.move()
46.         self.normalize()
47.
48.     def print(self, observed_req = 0):
49.         observed_points = len(list(filter(lambda v: v.x <= self.width and v.y <= self.height, self.points)))
50.         if observed_points < observed_req:
51.             return False
52.         for i in range(self.height):
53.             print()
54.             for j in range(self.width):
55.                 if any(filter(lambda v: v.x == j and v.y == i, self.points)):
56.                     print('#', end='')
57.                 else:
58.                     print('.', end='')
59.         print()
60.         return True
61.
62. if __name__ == '__main__':
63.     with open('in.txt') as f: