solution: 2025/7
Signed-off-by: Alix von Schirp <github@avonschirp.bootmedia.de>
This commit is contained in:
26
src/2025/7/1/index.ts
Normal file
26
src/2025/7/1/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
export default async function runner(inputPath: string) {
|
||||
const input = (await Bun.file(inputPath).text()).trimEnd();
|
||||
|
||||
const field: string[][] = []
|
||||
const splitters: string[] = []
|
||||
|
||||
input.split("\n").forEach(value => field.push(value.split("")));
|
||||
|
||||
field[0]!.forEach((c, i) => {
|
||||
if(c === "S") recurse(i, 0, field, splitters);
|
||||
})
|
||||
|
||||
console.log(splitters.length)
|
||||
}
|
||||
|
||||
function recurse(x: number, y: number, field: string[][], splitters: string[]){
|
||||
if(y<0 || y>=field.length || x<0 || x>field[y]!.length) return;
|
||||
if(field[y]![x] === "^") {
|
||||
if(splitters.includes(`${x}|${y}`)) return;
|
||||
splitters.push(`${x}|${y}`)
|
||||
recurse(x-1, y, field, splitters);
|
||||
recurse(x+1, y, field, splitters);
|
||||
return;
|
||||
}
|
||||
recurse(x, y+1, field, splitters);
|
||||
}
|
||||
26
src/2025/7/2/index.ts
Normal file
26
src/2025/7/2/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user