Files
advent-of-code-2025/day-1.py
2025-12-01 16:31:40 -05:00

58 lines
1.4 KiB
Python

class SafeBreaker:
def __init__(self):
self.value = 50
self.times_pointing_zero = 0
def move_dial(self, instruction: str) -> None:
direction = instruction[0]
multiplier = -1 if direction == "L" else 1
movement = int(instruction[1:])
self.times_pointing_zero += int(movement / 100)
movement_value = multiplier * (movement % 100)
# Move
original_value = self.value
self.value = self.value + movement_value
if self.value < 0:
if original_value != 0:
self.times_pointing_zero += 1
print("past 0")
self.value = 100 + self.value
elif self.value >= 100:
print("past 0")
self.times_pointing_zero += 1
self.value = self.value % 100
elif self.value == 0:
self.times_pointing_zero += 1
def get_password(self) -> int:
return self.times_pointing_zero
def crack_safe(self, instructions: list[str]) -> int:
for instruction in instructions:
self.move_dial(instruction)
print(instruction, self.value)
return self.get_password()
if __name__ == "__main__":
instructions = []
with open("./day-1.txt", "r") as file:
for line in file.readlines():
instructions.append(line.strip())
sb = SafeBreaker()
password = sb.crack_safe(instructions)
print(password)