commit b55f7e8386adf9e9c72ca5bf41f4381acbda5cef Author: Jess Friedersdorff Date: Mon Dec 1 23:10:08 2025 +0000 day 1: Day 1 solution. Also setup gitignore and readme. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c778900 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +input_* +.idea/ +__pycache__/ diff --git a/README.md b/README.md new file mode 100644 index 0000000..63742c0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +## My solutions to AoC 2025 - 12 puzzles, 2 variations per day in December 2025. + +*sigh* GLHF I guess? 🎄🎁🎅 diff --git a/day_1.py b/day_1.py new file mode 100644 index 0000000..3af47c9 --- /dev/null +++ b/day_1.py @@ -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) + + +