this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Solve D07P01

modamo 1c765155 2c6b1541

+33
+33
day07/part1.ts
··· 1 + import { readFileSync } from "fs"; 2 + 3 + const diagram = readFileSync("./input.txt", "utf8") 4 + .split(/\n/) 5 + .map((line) => line.split("")); 6 + 7 + let beams = new Set([{ r: 0, c: diagram[0].indexOf("S") }]); 8 + let totalSplitCount = 0; 9 + 10 + for (let i = 0; i < diagram.length - 1; i++) { 11 + const b = [...beams]; 12 + const newBeams = new Set(); 13 + 14 + for (let j = 0; j < b.length; j++) { 15 + if (diagram[b[j].r + 1][b[j].c] === "^") { 16 + if (b[j].c + 1 >= 0) { 17 + newBeams.add(JSON.stringify({ r: b[j].r + 1, c: b[j].c - 1 })); 18 + } 19 + 20 + if (b[j].c + 1 < diagram[i].length) { 21 + newBeams.add(JSON.stringify({ r: b[j].r + 1, c: b[j].c + 1 })); 22 + } 23 + 24 + totalSplitCount++; 25 + } else { 26 + newBeams.add(JSON.stringify({ r: b[j].r + 1, c: b[j].c })); 27 + } 28 + } 29 + 30 + beams = new Set([...newBeams].map((b) => JSON.parse(b))); 31 + } 32 + 33 + console.log(totalSplitCount);