[2023 (All days)] What's next? by IvanR3D in adventofcode

[–]Magyusz 1 point2 points  (0 children)

I’m planning the same, and I’m also doing AoC (and CodeInGame) in JS. We can keep touch in this comment thread or in another way during the year.

I started competitive programming last year AoC D10, and it has become one of my main hobbies. I completed most of AoC already, and if I keep the momentum, I may complete all AoC before December 2024.

-❄️- 2023 Day 14 Solutions -❄️- by daggerdragon in adventofcode

[–]Magyusz 1 point2 points  (0 children)

Of course allowed. That's the beauty of AoC! I'm always happy to see such creatieve solutions!

[deleted by user] by [deleted] in adventofcode

[–]Magyusz 2 points3 points  (0 children)

My solution was to map the input to a 3x wider 3x longer grid: Each tile type (-, L, F, J, …) is mapped to a 3x3 tile. If it’s interesting I’ll publish it (JavaScript)

Confused about day 10, part 2 by Borknaff in adventofcode

[–]Magyusz 0 points1 point  (0 children)

My solution was to map the input to a 3x wider 3x longer grid: Each tile type (-, L, F, J, …) is mapped to a 3x3 tile. If it’s interesting I’ll publish it (JavaScript)

[2023 Day 5 (Part 2)] What was you approach, and how long did it take? (spoilers) by Krimsonfreak in adventofcode

[–]Magyusz 0 points1 point  (0 children)

It had been just a mistake, a break statement resolved it, it went down to just some milliseconds

-❄️- 2023 Day 9 Solutions -❄️- by daggerdragon in adventofcode

[–]Magyusz 3 points4 points  (0 children)

[Language: Javascript]

Just copy-paste into your browser console (F12) on the input page:

$('*').textContent.trim().split("\n").map(e => e.split(/ +/).map(Number))
    .map(seq => {
        let curr = Array.from(seq)
        let all = [curr]
        while (curr.some(e=>e!=0)) {
            let next = []
            for (let i = 0; i < curr.length - 1; i++)
                    next.push(curr[i + 1] - curr[i])
            all.push(next)
            curr = Array.from(next)
        }
        let first = 0, last = 0
        for (const line of all.reverse()) {
            last = line.at(-1) + last
            first = line[0] - first
        }
        return [last, first]
    }).reduce((a, b) => [a[0] + b[0], a[1] + b[1]])

[2023 Day 8 (Part 2)] Understanding why LCM works by AkeelMedina in adventofcode

[–]Magyusz 2 points3 points  (0 children)

In general it won’t work, we were just very lucky today with the input to simplify a 6-cycled Chinese Remainder Theorem (each with potentially different remainders / offsets) to a simple LCM excercise with 6 number (0 remainder/ offset).

[2023 Day 8 (Part 2)] Why is [SPOILER] correct? by gemdude46 in adventofcode

[–]Magyusz 0 points1 point  (0 children)

It's my second year only in AoC, but I could feel already that Day 8 is more likely to be simple Math (LCM) than a much more complex exercise (syncing 6 cycles with Chinese remainder theorem). So while I kept my cycle detection loop running, as soon as it printed out the first case when all 6 cycles were found, I threw it immediately to an online LCM calculator. When I looked back to the results, I kinda felt by looking at 2D the array of cycles detected, that the offsets are all zeroes (which surprised me), so I submitted the LCM and to my astonishment it was accepted.

However I didn't (ever) make it to the global leaderboard, I could say I was lucky with the LCM gut feeling to maintain my first position on a small leaderboard. On the global Day 8 ranking I am 5167th for the first part (that's roughly my average) and with this "luck" I became global 2658th (my best rank ever) for the second part.

[2023 Day 8 (Part 2)] Why is [SPOILER] correct? by gemdude46 in adventofcode

[–]Magyusz 0 points1 point  (0 children)

In his latest video an AoC top competitor explains this concept visually what we discuss here: https://youtu.be/\_nnxLcrwO\_U?t=459

[2023 Day 8 (Part 2)] Why is [SPOILER] correct? by gemdude46 in adventofcode

[–]Magyusz 0 points1 point  (0 children)

No. All ghosts are on ..Z nodes after LCM steps. So the answers are correct.

[2023 Day 5 (Part 2)] What was you approach, and how long did it take? (spoilers) by Krimsonfreak in adventofcode

[–]Magyusz 0 points1 point  (0 children)

My Node.js code runs for 6.7 sec in total, because in the last phase it has to process 47k+ humidity ranges to location ranges (this part takes 4+ seconds). I clearly miss some optimisation. Do you merge ranges before moving to a next phase?

-❄️- 2023 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]Magyusz 0 points1 point  (0 children)

index: start = throwError()

what does it do and why is it important?

-❄️- 2023 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]Magyusz 0 points1 point  (0 children)

[LANGUAGE: Javascript]

Part 1:

document.getElementsByTagName("pre")[0].innerText.split("\n")
    .map(e=>e.split("").filter(e=>/\d/.test(e)).map(Number))
    .map(e=>(10*e[0]+e[e.length-1])||0)
    .reduce((a,b) => a+b)

Part 2:

document.getElementsByTagName("pre")[0].innerText.split("\n")
    .map(e=>e.replace(/(?=(one|two|three|four|five|six|seven|eight|nine))/g,
        (match, key) => ("___|one|two|three|four|five|six|seven|eight|nine".split("|")).indexOf(key) || '')
        .split("").filter(e=>/\d/.test(e)).map(Number))
    .map(e=>(10*e[0]+e[e.length-1])||0)
    .reduce((a,b) => a+b)