|
@@ -0,0 +1,29 @@
|
|
|
+from util import get_input
|
|
|
+from collections import namedtuple
|
|
|
+from more_itertools import flatten
|
|
|
+
|
|
|
+input = get_input("5.input")
|
|
|
+
|
|
|
+Point = namedtuple("Point", ['x', 'y'])
|
|
|
+
|
|
|
+input = [[Point(int(pair.split(",")[0]), int(pair.split(",")[1])) for pair in line.split(" -> ")] for line in input]
|
|
|
+
|
|
|
+maxx = max([p.x for p in flatten(input)])
|
|
|
+maxy = max([p.y for p in flatten(input)])
|
|
|
+board = [[0 for _ in range(maxy + 1)] for _ in range(maxx + 1)]
|
|
|
+
|
|
|
+def sign(n):
|
|
|
+ return 0 if n == 0 else (1 if n > 0 else -1)
|
|
|
+
|
|
|
+for line in input:
|
|
|
+ dx = sign(line[1].x - line[0].x)
|
|
|
+ dy = sign(line[1].y - line[0].y)
|
|
|
+ x = line[0].x
|
|
|
+ y = line[0].y
|
|
|
+ while x != line[1].x or y != line[1].y:
|
|
|
+ board[x][y] += 1
|
|
|
+ x += dx
|
|
|
+ y += dy
|
|
|
+ board[x][y] += 1
|
|
|
+
|
|
|
+print(sum([1 for num in flatten(board) if num > 1]))
|