Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 22, 2023
1 parent 41172c1 commit 9268337
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/2023/day21.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function solve(input, steps, infinite) {
}
let t = [];
let visited = new Map([[`${start.x},${start.y}`, start]]);
for (let i = 1; i <= steps && t.length < 3; i++) {
const max = steps > 5000 ? map.length * 2 + (steps % map.length) : steps;
for (let i = 1; i <= max; i++) {
const next = new Map();
for (const { x, y } of visited.values()) {
const neighbors = [
Expand All @@ -26,9 +27,9 @@ function solve(input, steps, infinite) {
neighbors.forEach(n => next.set(`${n.x},${n.y}`, n));
}
visited = next;
if (i === steps) return visited.size;
if (i % map.length === steps % map.length) t.push(visited.size);
}
if (t.length < 3) return visited.size;

// 1. 0^2*a + 0*b + c = t[0]
// 2. 1^2*a + 1*b + c = t[1]
Expand Down

0 comments on commit 9268337

Please sign in to comment.