mirror of
https://github.com/peter-tanner/advent-of-code-2023.git
synced 2024-11-30 14:00:16 +08:00
26 lines
692 B
TypeScript
26 lines
692 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
|
|
.replace(/ /g, "")
|
|
.split(":")
|
|
.map((token) => Number.parseInt(token))
|
|
.filter((token) => !isNaN(token));
|
|
const distances = distances_str
|
|
.replace(/ /g, "")
|
|
.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()));
|