(update) day 1

This commit is contained in:
2025-12-19 10:46:50 +01:00
parent e5bef6f3da
commit 424ea8e874
4 changed files with 4629 additions and 0 deletions

56
2025/01/main.py Normal file
View File

@ -0,0 +1,56 @@
#!/bin/env python3
# 0-99
MAX_NUMBERS = 100
START_AT = 50
with open("example", "+r") as file:
hit_zero = 0
position = START_AT
for line in file.readlines():
# print(line)
amount = int(line[1:])
direction = line[0]
no_rotations = int(amount / MAX_NUMBERS)
remaining = amount - no_rotations * MAX_NUMBERS
position = position - remaining if direction == "L" else position + remaining
if position < 0:
position = MAX_NUMBERS + position
if position >= MAX_NUMBERS:
position = position - MAX_NUMBERS
if position == 0:
hit_zero = hit_zero + 1
print(f"The dial is rotated {direction}{amount} to point at {position}")
print(f"hit 0 {hit_zero} times.")
with open("input", "+r") as file:
hit_zero = 0
position = START_AT
for line in file.readlines():
previous_position = position
amount = int(line[1:])
clockwise = True if line[0] == "R" else False
rotations = int(amount / MAX_NUMBERS)
remaining = amount - rotations * MAX_NUMBERS
position = position + remaining if clockwise else position - remaining
if (position <= 0 or position >= MAX_NUMBERS) and previous_position != 0:
rotations = rotations + 1
if position < 0:
position = MAX_NUMBERS + position
if position >= MAX_NUMBERS:
position = position - MAX_NUMBERS
hit_zero = hit_zero + rotations
print(
f'dial rotated {rotations}x {"clockwise" if clockwise else "counter-clockwise"} from {previous_position} to {position} ({amount})'
)
print(f"hit 0 {hit_zero} times.")