From f4e5be11bfd8d16210d1f519961c9a73a3933b0d Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 18 Dec 2024 23:24:08 +0000 Subject: [PATCH] Conflict --- 2024/18/index.ts | 52 ------------------------------------------------ 1 file changed, 52 deletions(-) diff --git a/2024/18/index.ts b/2024/18/index.ts index 73d4235..73a098c 100644 --- a/2024/18/index.ts +++ b/2024/18/index.ts @@ -215,56 +215,4 @@ while (openList.length > 0) { } printMap(); -<<<<<<< Updated upstream - -let fastest: number|null = null; - -const scoreCache: { [key: string]: [number, Coord, Dir] } = {}; - -const branchCache: { [key: string]: number } = {}; - -const scores: Array> = []; - -function getScoresAfterPosition(pos: Coord, dir: Dir, path: Array = [], lastBranch: [number, Coord]|null = null): void { - if (fastest !== null && path.length >= fastest) { - return; - } - const branch = isBranch(pos, dir); - if (branch) { - const cacheKey = `${pos.x},${pos.y},${dir}`; - const cache = branchCache[cacheKey]; - if (cache && cache < path.length) { - return; - } else { - branchCache[cacheKey] = path.length; - } - lastBranch = [path.length, pos]; - } - [dir, nextDir(dir), prevDir(dir)].forEach((newDir, i) => { - const next = nextCoord(pos, newDir); - if (!path.find(({ x, y }) => next.x === x && next.y === y)) { - if (next.x === width - 1 && next.y === height - 1) { - if (fastest === null || path.length < fastest) { - fastest = path.length; - } - scores.push(path); - return; - } else if (next.x >= 0 && next. x < width && next.y >= 0 && next.y < height && get(next) === '.') { - getScoresAfterPosition(next, newDir, [...path, next], lastBranch); - } - } - }); - - return; -} - -getScoresAfterPosition({ x: 0, y: 0 }, Dir.Up, [{ x: 0, y: 0 }]); - -console.log(scores); -const fastestScore = Math.min(...scores.map((p) => p.length)); -const fastestPath = scores.find((p) => p.length === fastestScore); -printMap(fastestPath); -console.log(fastestScore); -======= console.log(path, path.length) ->>>>>>> Stashed changes