AdventOfCode/JS/day1/solution_b.mjs
Tobias Berger c266d7c8ce
JavaScript Day 1
Signed-off-by: Tobias Berger <tobi.berger13@gmail.com>
2022-12-01 13:26:30 +01:00

27 lines
561 B
JavaScript

import fs from "fs";
/**
* Main function for Puzzle B
*
* @param {string} data - Puzzle input as a single string.
*/
async function main(data) {
const rows = data.split("\n").map((line) => parseInt(line));
for (const a of rows) {
for (const b of rows) {
for (const c of rows) {
if (a + b + c === 2020) {
return a * b * c;
}
}
}
}
throw new Error("No solution found!");
}
fs.readFile("input", (err, data) => {
if (err) throw err;
main(data.toString()).then(console.log).catch(console.error);
});