this repo has no description
0
fork

Configure Feed

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

Solve D03P02

modamo-gh 148d356c fa6de99d

+29
+29
day03/part2.ts
··· 1 + import { readFileSync } from "fs"; 2 + 3 + const banks = readFileSync("./input.txt", "utf8").split(/\n/).filter(Boolean); 4 + 5 + let totalJoltage = 0; 6 + 7 + for (const bank of banks) { 8 + const numberOfJolts = 12; 9 + 10 + let index = -1; 11 + 12 + const joltage: number[] = new Array(numberOfJolts).fill(-Infinity); 13 + 14 + for (let i = 0; i < joltage.length; i++) { 15 + let start = index + 1; 16 + let end = bank.length - (numberOfJolts - i) + 1; 17 + 18 + for (let j = start; j < end; j++) { 19 + if (Number(bank[j]) > joltage[i]) { 20 + joltage[i] = Number(bank[j]); 21 + index = j; 22 + } 23 + } 24 + } 25 + 26 + totalJoltage += Number(joltage.join("")); 27 + } 28 + 29 + console.log(totalJoltage);