end of day 3

This commit is contained in:
2025-12-03 23:36:36 -05:00
parent b87fb99001
commit 1b2b0f4edd
5 changed files with 260 additions and 4 deletions

43
day03/js/day03a.js Normal file
View File

@@ -0,0 +1,43 @@
import { promises as fsp } from "node:fs";
async function asyncReadFile(filename) {
try {
const contents = await fsp.readFile(filename, "utf-8");
return contents.trim();
} catch (err) {
console.error(err);
}
}
const findHighestOutput = (bank) => {
let arr = Array.from(bank);
let highest = 0;
arr.forEach((val, idx) => {
if (arr.length === idx + 1) return;
for (let i = idx + 1; i < arr.length; i++) {
const output = `${val}${arr[i]}` * 1;
if (output > highest) highest = output;
}
});
console.log(highest);
return highest;
};
/*
const dataToParse = `987654321111111
811111111111119
234234234234278
818181911112111`;
*/
const dataToParse = await asyncReadFile("../input.txt");
const banks = dataToParse.split("\n");
let total = 0;
banks.forEach((bank) => {
total += findHighestOutput(bank);
});
console.log(`Total: ${total}`);