From 31a8d2b6b7da1fcf4992a1fa6190eb3c7dbc4000 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 3 Dec 2025 09:39:50 +0100 Subject: Fixed day 1 part 2 --- day1/__init__.py | 33 ++++++++++++++++++--------------- 1 file 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): @staticmethod def calculate_new_position(position, rotation) -> tuple[int, int]: - previous_position = position - new_position = position + rotation - - overturned = new_position >= 100 or new_position < 0 - - multiplier = position - (0 - -previous_position) // 100 - - if overturned: - new_position = new_position % 100 - - seen_0 = 0 - if new_position == 0 and multiplier == 0: - seen_0 += multiplier + 1 - elif overturned: - seen_0 += multiplier + abs_rotation = abs(rotation) + seen_0 = abs(abs_rotation // 100) + + if rotation > 0: + remainder_rotation = rotation - (seen_0 * 100) + elif rotation < 0: + remainder_rotation = rotation + (seen_0 * 100) + else: + remainder_rotation = 0 + + new_position = (position + remainder_rotation) % 100 + + if remainder_rotation != 0 and new_position == 0: + seen_0 += 1 + elif position > 0 and rotation > 0 and position > new_position: + seen_0 += 1 + elif position > 0 and rotation < 0 and position < new_position: + seen_0 += 1 return new_position, seen_0 -- cgit v1.2.3