aoc-2023/day_12/solve_2.ts
2024-12-09 22:41:02 +09:00

28 lines
820 B
TypeScript

import { Solver, State } from "./solver.ts";
const input = await Deno.readTextFile("input.txt");
const lines = input.split("\n").map(x => x.trim()).filter(x => x.length > 0);
function repeatArray<T>(s: T, n: number): T[] {
let ret = [];
for (let i = 0; i < n; i++) {
ret.push(s);
}
return ret;
}
const datas = lines.map(x => {
const [statesStr, groupsStr] = x.split(" ");
const copies = 5;
return {
state: repeatArray(statesStr, 5).join("?").split(""),
group: repeatArray(groupsStr.split(",").map(x => parseInt(x)), 5).flat()
};
})
const ways = datas.map(data => {
const ret = new Solver(data.state as State[], data.group).solve(0, 0);
console.log(data.state.join(""), data.group, ret);
return ret;
});
console.log(ways.reduce((a, b) => a + b, 0));