Zum Hauptinhalt springen
YouTube Security VideosAnonymous Official: Something Strange Is Happening Right Now in America(03.10.2026 um 21:30 Uhr)
•
Sichere ProgrammierungAzure ExpressRoute Gateway(03.10.2026 um 21:39 Uhr)
••
AI & KI NachrichtenThings I wish my Dot could do(03.10.2026 um 21:45 Uhr)
••
Sichere ProgrammierungI Lost Access to My Email. Here's How It Changed My Career Path(03.10.2026 um 21:45 Uhr)
•
Sichere ProgrammierungHow a race condition stopped UK air traffic control for six hours(03.10.2026 um 21:46 Uhr)
•
Sichere ProgrammierungBlender for Developers: 15 Concepts Explained Simply(03.10.2026 um 21:49 Uhr)
••
Sichere ProgrammierungEcco the Dolphin: The Genesis Game That Turned Sonar Into a Superpower(03.10.2026 um 21:50 Uhr)
•
YouTube Security VideosAnonymous Official: Something Strange Is Happening Right Now in America(03.10.2026 um 21:30 Uhr)
•
Sichere ProgrammierungAzure ExpressRoute Gateway(03.10.2026 um 21:39 Uhr)
••
AI & KI NachrichtenThings I wish my Dot could do(03.10.2026 um 21:45 Uhr)
••
Sichere ProgrammierungI Lost Access to My Email. Here's How It Changed My Career Path(03.10.2026 um 21:45 Uhr)
•
Sichere ProgrammierungHow a race condition stopped UK air traffic control for six hours(03.10.2026 um 21:46 Uhr)
•
Sichere ProgrammierungBlender for Developers: 15 Concepts Explained Simply(03.10.2026 um 21:49 Uhr)
••
Sichere ProgrammierungEcco the Dolphin: The Genesis Game That Turned Sonar Into a Superpower(03.10.2026 um 21:50 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Secret Entrance

Advent of Code 2025 Day 1 Part 1 Round and round we go! Let's dive straight in to this one. The challenge models a number line from 0 to 99 - 100 numbers.…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!




Advent of Code 2025 Day 1






Part 1






Round and round we go!



Let's dive straight in to this one.



The challenge models a number line from 0 to 99 - 100 numbers.



Moving past 0 - to the left - should be equivalent to looping back to 99 and counting down.



The example given is:

L5 from 0 lands you on 95



How might I accomplish that with computer code?



Well:





  • 0 - 5 is -5

  • If the number is negative...

  • Calculate 100 minus the absolute value of that number

  • So, 100 - (+5) or 100 - 5 or 95



Another example is:

R5 from 99 lands you on 4



How might I accomplish that with computer code?



Well:





  • 99 + 5 is 104

  • If the number is greater than 100...

  • Calculate the number modulo 100 - dividing the number by 100 and keeping the remainder

  • So, 104 % 100 is 4



An example of a large rotation from my input is:

L888 from, say, 42, lands you on 54



How might I accomplish that with computer code?



Well:




  • A combination of both techniques above

  • First performing the modulo on 888 to get: 88 - each additional 100 rotations will result in the same landing spot

  • Calculating 42 - 88 as -46

  • Calculating 100 - (+46) as 54



I can use the modulo technique any time the rotation is greater than 99.



I'm ready to turn all this logic into working computer code.





Writing my algorithm



Setting up variables:




input = input.split('\n')
let cursor = 50
let password = 0






Parsing each instruction:




input.forEach(rotation => {
let dir = rotation[0]
let amt = +rotation.slice(1) % 100
})






Writing the conditional logic:




input.forEach(rotation => {
let dir = rotation[0]
let amt = +rotation.slice(1) % 100
switch (dir) {
case "R":
cursor = (cursor + amt) % 100
break;
case "L":
cursor = (cursor - amt < 0) ? 100 - Math.abs(cursor - amt) : cursor - amt
break;
}
if (cursor == 0) {
password++
}
})






I forgot about the use case of a L instruction that doesn't result in a negative number.



That took a few minutes of debugging, and resulted in the ternary operation shown above.



After testing on the example input, it works as expected.



Will it work correctly on my puzzle input, though?






Testing on my puzzle input



Running...



Submitting...



Correct!



Woohoo!!!






Part 2






Of course, now number of rotations is critical



I now am forced to care about the numbers I was modulo-ing away in Part 1.



Use cases I have to identify:




  • An R instruction that passes 99

  • An L instruction that passes 0

  • Any instructions greater than 99

  • Instructions perfectly divisible by 100 when the cursor is 0






Updating my algorithm



I went straight to it.



Here's what I wrote:




input.forEach(rotation => {
let dir = rotation[0]
let amt = +rotation.slice(1)

if (amt.toString().length > 2) {
let temp = amt.toString()
password += +temp.slice(0, amt.length - 2)
amt = amt % 100
}
let next
switch (dir) {
case "R":
next = (cursor + amt) % 100
if (next < cursor) {
password++
}
cursor = next
break;
case "L":
next = (cursor - amt < 0) ? 100 - Math.abs(cursor - amt) : cursor - amt
if (next > cursor) {
password++
}
cursor = next
break;
}
})







  • First, I handle rotation amounts over 99

  • Then, in each case, I determine where the cursor will end up, and update the password if it has crossed 0






Testing my algorithm



It generates the correct answer for the example puzzle input.



It generates an answer that is twice what I Part 1 answer was. That seems low.



Still, it could be right.



Submitting...



Wrong answer. Too low.






Am I overthinking things?



Upon inspecting my input:




  • Nearly 800 instructions rotate the cursor more than 100 notches, meaning at least pass across 0

  • No rotations of 0 notches, which could have been an edge case I didn't account for

  • No rotations that are perfectly divisible by 100, which I think my code still accounts for



So, I have two sets of instructions:




  1. A number less than 100 resulting in 0-1 passes across 0

  2. A number greater than 100 resulting in 1+ passes across 0



Time to re-think and step through my algorithm.






Fixing my mistakes one by one




  • Wrong condition logic

  • Wrong variable used

  • Missing part of condition



Man, I really overlooked some critical details.



Thankfully, the example input helped me see my final glaring error.



Alas, this is the algorithm that allowed me to generate the correct answer:




input.forEach(rotation => {
let dir = rotation[0]
let amt = +rotation.slice(1)

if (amt.toString().length > 2) {
let temp = amt.toString()
password += +temp.slice(0, amt.toString().length - 2)
amt = amt % 100
}
let next
switch (dir) {
case "R":
next = cursor + amt
if (next >= 100) {
password++
}
cursor = (next >= 100) ? next - 100 : next
break;
case "L":
next = cursor - amt
if (cursor > 0 && next <= 0) {
password++
}
cursor = (next < 0) ? 100 - Math.abs(cursor - amt) : next
break;
}
})







  • I correctly increment the password for each hundred in large instructions

  • For L rotations, I correctly only increment password when the cursor is at a position higher than 0

  • For L rotations, I correctly update the cursor's value when it crosses 0



This was the most I've had to troubleshoot a Day 1 Part 2 algorithm.



I have only myself to blame. I simply overlooked a lot of important subtleties.



Thankfully, I come away with two gold stars!



The year is off to a great start!

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Secret Entrance

Thematisch verwandte Begriffe: Secret, Entrance · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag