|
1 | 1 | export default function solve(input: string) { |
2 | 2 | const rows = input.split("\n").map((line) => Array.from(line)); |
3 | | - const beamColumnIndexes = new Map([[rows[0].indexOf("S"), 1]]); |
| 3 | + const timelineCounts = new Map([[rows[0].indexOf("S"), 1]]); |
4 | 4 | for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) { |
5 | | - for (const [beamColumnIndex, timelineCount] of beamColumnIndexes) { |
| 5 | + for (const [beamColumnIndex, timelineCount] of timelineCounts) { |
6 | 6 | if (rows[rowIndex + 1]?.[beamColumnIndex] !== "^") continue; |
7 | | - beamColumnIndexes.delete(beamColumnIndex); |
| 7 | + timelineCounts.delete(beamColumnIndex); |
8 | 8 | for (const direction of [-1, 1]) { |
9 | 9 | const splitColumnIndex = beamColumnIndex + direction; |
10 | | - const prevTimelineCount = beamColumnIndexes.get(splitColumnIndex); |
| 10 | + const prevTimelineCount = timelineCounts.get(splitColumnIndex); |
11 | 11 | const nextTimelineCount = (prevTimelineCount ?? 0) + timelineCount; |
12 | | - beamColumnIndexes.set(splitColumnIndex, nextTimelineCount); |
| 12 | + timelineCounts.set(splitColumnIndex, nextTimelineCount); |
13 | 13 | } |
14 | 14 | } |
15 | 15 | } |
16 | | - return beamColumnIndexes.values() |
17 | | - .reduce((sum, timelineCount) => sum + timelineCount, 0); |
| 16 | + return timelineCounts.values().reduce((sum, count) => sum + count, 0); |
18 | 17 | } |
0 commit comments