day 1: Day 1 solution. Also setup gitignore and readme.

This commit is contained in:
Jess Friedersdorff 2025-12-01 23:10:08 +00:00
commit b55f7e8386
3 changed files with 80 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
input_*
.idea/
__pycache__/

3
README.md Normal file
View file

@ -0,0 +1,3 @@
## My solutions to AoC 2025 - 12 puzzles, 2 variations per day in December 2025.
*sigh* GLHF I guess? 🎄🎁🎅

74
day_1.py Normal file
View file

@ -0,0 +1,74 @@
"""
Work out password
"""
def turn_dial(start_number: int, movement: str) -> tuple[int, int]:
"""
If L increase numbers, if R decrease numbers
"""
direction = movement[0]
turn = int(movement[1:])
remainder = turn % 100
times_turned = int(turn / 100)
if direction == 'R':
new_number = start_number + remainder
if new_number > 99:
new_number = new_number - 100
times_turned += 1
else:
new_number = start_number - remainder
if new_number < 0:
new_number = 100 - abs(new_number)
if start_number != 0:
times_turned += 1
elif new_number == 0 and start_number != 0:
times_turned += 1
return new_number, times_turned
def get_password_1(file_path):
password = 0
with open(file_path) as in_file:
previous_number = 50
for line in in_file:
previous_number, _ = turn_dial(previous_number, line)
if previous_number == 0:
password += 1
return password
def get_password_2(file_path):
password = 0
with open(file_path) as in_file:
previous_number = 50
for line in in_file:
previous_number, turns = turn_dial(previous_number, line)
password += turns
return password
def test_get_password_1():
print(get_password_1('input_test.txt'))
print(get_password_1('input_day1.txt'))
def test_get_password_2():
assert get_password_2('input_test.txt') == 6
print(get_password_2('input_day1.txt'))
def test_turn_dial():
assert turn_dial(50, 'L68') == (82, 1)
assert turn_dial(82, 'L30') == (52, 0)
assert turn_dial(52, 'R48') == (0, 1)
assert turn_dial(0, 'R100') == (0, 1)
assert turn_dial(0, 'R1000') == (0, 10)
assert turn_dial(0, 'L100') == (0, 1)
assert turn_dial(50, 'R150') == (0, 2)
assert turn_dial(0, 'R50') == (50, 0)
assert turn_dial(5, 'L10') == (95, 1)
assert turn_dial(5, 'L5') == (0, 1)
assert turn_dial(0, 'L5') == (95, 0)