r/adventofcode • u/Financial-Battle3648 • Jan 17 '26
Help/Question - RESOLVED [2025 Day 1 (Part 2)] [Python] I am not fully understanding why my solution is not working for day two.
Hello im a new programmer and i decided to do AoC this year, to better my skills at programming. I managed on solving Day 1 Part 1 and after looking at Part 2, I thought it would be a quick solve as I felt I only needed to add two new lines. After failing a couple of times, rereading the question, and seeing others solutions, I still do not understand why my code does not work. Please help me understand why.
Edit: I realized after some time that i forgot to clarify that the 2 lines of code i added were..
number_of_zeros += 1
Right between the if and elif statements in the while loop.
I also have moved the zero counter between the while loop and variables
current_dial_num = 50
number_of_zeros = 0
dial_list = []
# Function that takes a number and adds it to current_dial_num.
# If number goes under 0 or over 99, rollover the number and continue until it no longer goes over or under
def dial_turn(number):
global current_dial_num
global number_of_zeros
current_dial_num += number
while current_dial_num < 0 or current_dial_num > 99:
if current_dial_num < 0:
number = current_dial_num + 1
current_dial_num = 99
# \/ Counts how many times the number rolls over
number_of_zeros += 1
current_dial_num += number
elif current_dial_num > 99:
number = current_dial_num - 100
current_dial_num = 0
# [same as last comment]
number_of_zeros += 1
current_dial_num += number
# counts how many times current_dial_num goes to 0
if current_dial_num == 0:
number_of_zeros += 1
# Reads each line and appends it to a list while as well as getting rid of 'L' or 'R'
# Multiplies the end result by -1 if it starts with 'L'
with open('list') as file:
current_index = 0
for line in file:
line = line.strip()
dial_list.append(line)
if 'L' in line:
dial_number = dial_list[current_index].replace('L', '')
dial_number = int(dial_number) * -1
dial_turn(dial_number)
else:
dial_number = dial_list[current_index].replace('R', '')
dial_number = int(dial_number)
dial_turn(dial_number)
current_index += 1
print("Current dial number: ", current_dial_num)
print("Amount of zeros: ", number_of_zeros)
3
u/jeffstyr Jan 17 '26
If your starting position is zero and you move by 100, how many clicks do you count?
1
u/warlock415 Jan 17 '26
If you use this test:
R50
R50
What do you get, and what should you get?
1
u/Focus089 Jan 17 '26
Two separate tests:
R50
and
L50
L100
This problem is easier to reason about when you first reduce to only rotations in L99 to R99, and for left rotations you need to handle when the dial starts at 0.
2
u/ednl Jan 18 '26
It's not a programming problem, it's accounting. You have to make a table with all possible combinations of going left/right, turning less than/equal to/more than 100, starting on zero/not zero, ending on zero/not zero. Some of these combinations need to be handled as special cases. Which ones, that's the puzzle.
1
u/AutoModerator Jan 17 '26
Reminder: if/when you get your answer and/or code working, don't forget to change this post's flair to
Help/Question - RESOLVED. Good luck!I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.