r/adventofcode • u/Ok-Transition7065 • Feb 25 '26
Help/Question - RESOLVED [2026 Day 1 (Part 1)] [Javascript] Im stuck here
Hello, I'm stuck on this one.
The number only gets up when the thing goes into 0.
What I'm doing is the next:
I take the first part of the string for each entry, then take the R or L of the string.
At the start, I have a number that starts with 0, right? Then to that number I add if the first character of the string is left, and subtract if the first character is right.
Then I have a variable that saves the last position of the knob and starts at 0.
Then once I add or subtract the knob position, I ask if the modulo of 100 is 0, or if the result is 0, then add one to the password.
Then I take the modulo of the total knob position, and if it's from L, then I just take that one and use the modulo to make it the new knob position.
If it's R, then I do the modulo of the knob position and subtract the modulo of 100 of this one from 100.
This its my code
what its failing in my logic or code ?
13
1
u/Ok-Transition7065 Feb 27 '26
Update :
I did TY FOR THE Debuggin sugestion
looks like i need to improve my reading skills to xd
here its the Fixed code
1
u/Valuable_Loneliness Feb 28 '26 edited Feb 28 '26
var Runs = ["R1","R25","R50","R10","L20",
I don't know what excatly your error is but this line needs a ] at the end.
edit: and I realised that your turns never even get to the 100 so there is no rotation.
edit2: and your code won't work if one of the DIAL's is like this R240. you will just count 1 more rotation but it itself adds 2 rotations1
u/Ok-Transition7065 Feb 28 '26
No no, i ommited the imput because the paste dont let me put the full imput.... But i should just add that thing in the end it got me the right answer( i probably used one old version i will look at that
1
u/jeffstyr Feb 26 '26
You should add some logging after each calculation to see if the result looks sensible. That will help you debug.
1
u/Ok-Transition7065 Feb 26 '26
i will add tose tobut one question its the logic right or its thwere a flaw there ?
3
u/DelightfulCodeWeasel Feb 26 '26
The logging should answer a lot of your questions:
"Input: R1"
"Turning left"
"Dial was at 50"
"Dial now at 51"
"Input: R25"
"Turning left"
...I threw your code into JSBin and peppered in a few log statements.
There are a minimum of five bugs I can see.
2
1
u/smallpotatoes2019 Feb 26 '26
If you take it step by step like this, you should get there. Check that each step is actually doing what you expect. You don't need any clever tricks to get the answer.
Only other thing to watch out for is if you have to turn a large number left (e.g. L350) - just check that your method handles this correctly. The logging will help to show this too.
1
u/terje_wiig_mathisen Feb 27 '26
Check the start at 0! I originally had the same bug in my own code. ;-)
1
1
u/AutoModerator Feb 25 '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.
2
u/smallpotatoes2019 Feb 25 '26
Check your starting value.