AoE 2025 Day 1 Part 2. What did I missed?
04:21 26 Jan 2026

Can't figure out what went wrong. My result is higher than the correct one by almost 2000.

Thanks in advance.

let steps = document.querySelector('pre').innerHTML.replace(/ /g,'').split('\n');
    steps.pop();

    // Solution
    let current = 50;
    let result = 0;

    steps.forEach(step => {
        let numberOfRoundPerStep = 0;
        const direction = step[0];
        const tick = Number(step.slice(1));

        if (direction === "L") current -= tick; 
        else current += tick;
    
        if (current >= 100) {
            result += (current - current % 100) / 100; // add number of time pass 0
            current = current % 100; // set new position
        } else if (current < 0) {
            result += Math.abs((current - current % 100) / 100) + 1; // add number of time pass 0
            current = 100 + current % 100; // set new position
        } else if (current === 0) {
            result += 1;
        }
    })

    console.log('result', result);
javascript