diff options
| author | 2022-12-12 21:18:08 +0100 | |
|---|---|---|
| committer | 2022-12-12 21:18:08 +0100 | |
| commit | 9ba6ef9d5eeb1e093b2072c10b5092d829594d3b (patch) | |
| tree | 836dcb473bb39b2bdca26a9e69a14aea16eadd27 /day9/__init__.py | |
| parent | 968ade2c193d80db7a6170ee1eb44e120aa00992 (diff) | |
| download | 2022-9ba6ef9d5eeb1e093b2072c10b5092d829594d3b.tar.gz 2022-9ba6ef9d5eeb1e093b2072c10b5092d829594d3b.tar.bz2 2022-9ba6ef9d5eeb1e093b2072c10b5092d829594d3b.zip | |
Day 9
Diffstat (limited to 'day9/__init__.py')
| -rw-r--r-- | day9/__init__.py | 13 |
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)] |
