advent-of-code-2023/day_6/part_1.ts
2023-12-06 14:48:18 +08:00

24 lines
646 B
TypeScript

import * as fs from "fs";
import { Race, solve_all_races } from "./solver";
export const read_file = () => {
const input = fs.readFileSync("input", "ascii");
const [times_str, distances_str] = input.split("\n");
const times = times_str
.split(" ")
.map((token) => Number.parseInt(token))
.filter((token) => !isNaN(token));
const distances = distances_str
.split(" ")
.map((token) => Number.parseInt(token))
.filter((token) => !isNaN(token));
const races: Race[] = times.map((time, i) => {
return { time: time, distance: distances[i] };
});
return races;
};
console.log(solve_all_races(read_file()));