diff options
Diffstat (limited to 'day9')
| -rw-r--r-- | day9/__init__.py | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/day9/__init__.py b/day9/__init__.py index a2d6d82..ba29708 100644 --- a/day9/__init__.py +++ b/day9/__init__.py | |||
| @@ -36,26 +36,18 @@ class Assignment(BaseAssignment, ABC): | |||
| 36 | if abs(delta.x) < 2 and abs(delta.y) < 2: | 36 | if abs(delta.x) < 2 and abs(delta.y) < 2: |
| 37 | return tail | 37 | return tail |
| 38 | elif abs(delta.x) > 1 and delta.y == 0: | 38 | elif abs(delta.x) > 1 and delta.y == 0: |
| 39 | return tail + Coordinate( | 39 | return tail + delta - delta.polarity |
| 40 | delta.x - delta.polarity_x, | ||
| 41 | 0, | ||
| 42 | ) | ||
| 43 | elif abs(delta.x) > 1 and abs(delta.y) == 1: | 40 | elif abs(delta.x) > 1 and abs(delta.y) == 1: |
| 44 | return tail + Coordinate(delta.x - delta.polarity_x, delta.y) | 41 | return tail + Coordinate(delta.x - delta.polarity.x, delta.y) |
| 45 | elif abs(delta.y) > 1 and delta.x == 0: | 42 | elif abs(delta.y) > 1 and delta.x == 0: |
| 46 | return tail + Coordinate( | 43 | return tail + delta - delta.polarity |
| 47 | 0, | ||
| 48 | delta.y - delta.polarity_y, | ||
| 49 | ) | ||
| 50 | elif abs(delta.y) > 1 and abs(delta.x) == 1: | 44 | elif abs(delta.y) > 1 and abs(delta.x) == 1: |
| 51 | return tail + Coordinate( | 45 | return tail + Coordinate( |
| 52 | delta.x, | 46 | delta.x, |
| 53 | delta.y - delta.polarity_y, | 47 | delta.y - delta.polarity.y, |
| 54 | ) | 48 | ) |
| 55 | elif abs(delta.x) > 1 and abs(delta.y) > 1: | 49 | elif abs(delta.x) > 1 and abs(delta.y) > 1: |
| 56 | return tail + Coordinate( | 50 | return tail + delta - delta.polarity |
| 57 | delta.x - delta.polarity_x, delta.y - delta.polarity_y | ||
| 58 | ) | ||
| 59 | 51 | ||
| 60 | def tail_positions(self, input: Iterator[str], length: int) -> Iterator[Coordinate]: | 52 | def tail_positions(self, input: Iterator[str], length: int) -> Iterator[Coordinate]: |
| 61 | knots = [Coordinate(0, 0) for _ in range(length)] | 53 | knots = [Coordinate(0, 0) for _ in range(length)] |
