AdventOfCode/JS/day5/solution_a.mjs
Tobias Berger c8582e5234
JavaScript Day 5
Signed-off-by: Tobias Berger <tobi.berger13@gmail.com>
2022-12-01 13:26:31 +01:00

22 lines
594 B
JavaScript

import fs from "fs";
/**
* Main function for Puzzle A
*
* @param {string} data - Puzzle input as a single string.
* @returns {number} The highest Seat ID in the puzzle input.
*/
async function main(data) {
const entries = data
.split(/\r?\n/)
.map((line) => line.replace(/[FL]/g, "0").replace(/[BR]/g, "1"))
.map((line) => line.match(/^(?<y>[01]{7})(?<x>[01]{3})$/))
.map((entry) => parseInt(entry[0], 2));
return Math.max(...entries);
}
fs.readFile("input", (err, data) => {
if (err) throw err;
main(data.toString()).then(console.log).catch(console.error);
});