diff options
| author | 2025-12-03 09:39:50 +0100 | |
|---|---|---|
| committer | 2025-12-03 09:40:57 +0100 | |
| commit | 31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000 (patch) | |
| tree | 1492f42414832c4eeba4d844217067877077ca65 /day1/__init__.py | |
| parent | f315ef05c548da80410cb4f6665a9bba7a953f94 (diff) | |
| download | 2025-31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000.tar.gz 2025-31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000.tar.bz2 2025-31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000.zip | |
Fixed day 1 part 2
Diffstat (limited to 'day1/__init__.py')
| -rw-r--r-- | day1/__init__.py | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/day1/__init__.py b/day1/__init__.py index 6e95329..ec1c2f2 100644 --- a/day1/__init__.py +++ b/day1/__init__.py | |||
| @@ -32,21 +32,24 @@ class AssignmentTwo(Assignment): | |||
| 32 | 32 | ||
| 33 | @staticmethod | 33 | @staticmethod |
| 34 | def calculate_new_position(position, rotation) -> tuple[int, int]: | 34 | def calculate_new_position(position, rotation) -> tuple[int, int]: |
| 35 | previous_position = position | 35 | abs_rotation = abs(rotation) |
| 36 | new_position = position + rotation | 36 | seen_0 = abs(abs_rotation // 100) |
| 37 | 37 | ||
| 38 | overturned = new_position >= 100 or new_position < 0 | 38 | if rotation > 0: |
| 39 | 39 | remainder_rotation = rotation - (seen_0 * 100) | |
| 40 | multiplier = position - (0 - -previous_position) // 100 | 40 | elif rotation < 0: |
| 41 | 41 | remainder_rotation = rotation + (seen_0 * 100) | |
| 42 | if overturned: | 42 | else: |
| 43 | new_position = new_position % 100 | 43 | remainder_rotation = 0 |
| 44 | 44 | ||
| 45 | seen_0 = 0 | 45 | new_position = (position + remainder_rotation) % 100 |
| 46 | if new_position == 0 and multiplier == 0: | 46 | |
| 47 | seen_0 += multiplier + 1 | 47 | if remainder_rotation != 0 and new_position == 0: |
| 48 | elif overturned: | 48 | seen_0 += 1 |
| 49 | seen_0 += multiplier | 49 | elif position > 0 and rotation > 0 and position > new_position: |
| 50 | seen_0 += 1 | ||
| 51 | elif position > 0 and rotation < 0 and position < new_position: | ||
| 52 | seen_0 += 1 | ||
| 50 | 53 | ||
| 51 | return new_position, seen_0 | 54 | return new_position, seen_0 |
| 52 | 55 | ||
