Created
December 11, 2025 22:59
-
-
Save MaxArt2501/ee1569e67294dec091871bfa06d6b3db to your computer and use it in GitHub Desktop.
Advent of Code 2025 - Day 11 - Iterative "solution"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // It actually doesn't work for part 2 | |
| const devices = new Map( | |
| input.trim().split('\n').concat('out').map(line => { | |
| const [device, ...outputs] = line.split(/\W+/); | |
| return [device, outputs]; | |
| }) | |
| ); | |
| const countPaths = (start, end = 'out') => { | |
| let frontier = new Set([start]); | |
| const visited = new Map([[start, 1]]); | |
| while (frontier.size) { | |
| const newFrontier = new Set(); | |
| for (const device of frontier) { | |
| const count = visited.get(device); | |
| for (const output of devices.get(device)) { | |
| newFrontier.add(output); | |
| visited.set(output, (visited.get(output) ?? 0) + count); | |
| } | |
| } | |
| frontier = newFrontier; | |
| } | |
| return visited.get(end) ?? 0; | |
| }; | |
| // Part one: it works | |
| console.log(countPaths('you', 'out')); | |
| // Part two: it doesn't. Why?! | |
| console.log( | |
| countPaths('svr', 'fft') * countPaths('fft', 'dac') * countPaths('dac', 'out') + | |
| countPaths('svr', 'dac') * countPaths('dac', 'fft') * countPaths('fft', 'out') | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment