From 9ba6ef9d5eeb1e093b2072c10b5092d829594d3b Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Mon, 12 Dec 2022 21:18:08 +0100 Subject: Day 9 --- day9/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'day9/__init__.py') 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): def next_knot(head: Coordinate, tail: Coordinate): delta = head - tail - if abs(delta.x) > 1 and delta.y == 0: + if abs(delta.x) < 2 and abs(delta.y) < 2: + pass + elif abs(delta.x) > 1 and delta.y == 0: tail.x += delta.x - delta.polarity_x - if abs(delta.x) > 1 and abs(delta.y) == 1: + elif abs(delta.x) > 1 and abs(delta.y) == 1: tail.x += delta.x - delta.polarity_x tail.y += delta.y - if abs(delta.y) > 1 and delta.x == 0: + elif abs(delta.y) > 1 and delta.x == 0: tail.y += delta.y - delta.polarity_y - if abs(delta.y) > 1 and abs(delta.x) == 1: + elif abs(delta.y) > 1 and abs(delta.x) == 1: tail.y += delta.y - delta.polarity_y tail.x += delta.x + elif abs(delta.x) > 1 and abs(delta.y) > 1: + tail.x += delta.x - delta.polarity_x + tail.y += delta.y - delta.polarity_y def tail_positions(self, input: Iterator[str], length: int) -> Iterator[Coordinate]: knots = [Coordinate(0, 0) for _ in range(length)] -- cgit v1.2.3