27 lines
875 B
TypeScript
27 lines
875 B
TypeScript
export default async function runner(inputPath: string) {
|
|
const input = (await Bun.file(inputPath).text()).trimEnd();
|
|
|
|
const field: string[][] = []
|
|
const splitters: Map<string, number> = new Map()
|
|
|
|
input.split("\n").forEach(value => field.push(value.split("")));
|
|
|
|
field[0]!.forEach((c, i) => {
|
|
if(c === "S") console.log(recurse(i, 0, field, splitters));
|
|
})
|
|
}
|
|
|
|
function recurse(x: number, y: number, field: string[][], splitters: Map<string, number>){
|
|
if(y>=field.length) return 1;
|
|
if(y<0 || x<0 || x>field[y]!.length) return 0;
|
|
if(field[y]![x] === "^") {
|
|
let paths = 0;
|
|
if(splitters.has(`${x}|${y}`)) return splitters.get(`${x}|${y}`)!;
|
|
paths += recurse(x-1, y, field, splitters);
|
|
paths += recurse(x+1, y, field, splitters);
|
|
splitters.set(`${x}|${y}`, paths)
|
|
return paths;
|
|
}
|
|
return recurse(x, y+1, field, splitters);
|
|
}
|