summaryrefslogtreecommitdiffstats
path: root/day9/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'day9/__init__.py')
-rw-r--r--day9/__init__.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/day9/__init__.py b/day9/__init__.py
index 4846468..e0f1d61 100644
--- a/day9/__init__.py
+++ b/day9/__init__.py
@@ -59,16 +59,21 @@ class Assignment(BaseAssignment, ABC):
59 def next_knot(head: Coordinate, tail: Coordinate): 59 def next_knot(head: Coordinate, tail: Coordinate):
60 delta = head - tail 60 delta = head - tail
61 61
62 if abs(delta.x) > 1 and delta.y == 0: 62 if abs(delta.x) < 2 and abs(delta.y) < 2:
63 pass
64 elif abs(delta.x) > 1 and delta.y == 0:
63 tail.x += delta.x - delta.polarity_x 65 tail.x += delta.x - delta.polarity_x
64 if abs(delta.x) > 1 and abs(delta.y) == 1: 66 elif abs(delta.x) > 1 and abs(delta.y) == 1:
65 tail.x += delta.x - delta.polarity_x 67 tail.x += delta.x - delta.polarity_x
66 tail.y += delta.y 68 tail.y += delta.y
67 if abs(delta.y) > 1 and delta.x == 0: 69 elif abs(delta.y) > 1 and delta.x == 0:
68 tail.y += delta.y - delta.polarity_y 70 tail.y += delta.y - delta.polarity_y
69 if abs(delta.y) > 1 and abs(delta.x) == 1: 71 elif abs(delta.y) > 1 and abs(delta.x) == 1:
70 tail.y += delta.y - delta.polarity_y 72 tail.y += delta.y - delta.polarity_y
71 tail.x += delta.x 73 tail.x += delta.x
74 elif abs(delta.x) > 1 and abs(delta.y) > 1:
75 tail.x += delta.x - delta.polarity_x
76 tail.y += delta.y - delta.polarity_y
72 77
73 def tail_positions(self, input: Iterator[str], length: int) -> Iterator[Coordinate]: 78 def tail_positions(self, input: Iterator[str], length: int) -> Iterator[Coordinate]:
74 knots = [Coordinate(0, 0) for _ in range(length)] 79 knots = [Coordinate(0, 0) for _ in range(length)]