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

25 lines
681 B
JavaScript

import fs from "fs";
/**
* Main function for Puzzle B
*
* @param {string} data - Puzzle input as a single string.
* @returns {Promise<string>} Equation to get the final result. Needs to be solved elsewhere.
*/
async function main(data) {
const input = data.split(/\r?\n/)[1];
const buses = input
.split(",")
.map((val) => parseInt(val))
.map((id, i) => (isNaN(id) ? null : `(t+${i}) mod ${id} == 0`))
.filter((val) => val !== null);
const eq = buses.join(" && ");
// Solve elsewhere
// WolframAlpha works
return eq;
}
fs.readFile("input", (err, data) => {
if (err) throw err;
main(data.toString()).then(console.log).catch(console.error);
});