function cumulativeSpiralLargerThan(target) {
let grid = { "0,0": 1 };
let adj = AOC.gAdjacency();
let n = 1;
while (true) {
const root = Math.floor(Math.sqrt(n));
const ring = Math.floor((root + (root % 2)) / 2);
const maxInRing = 4 * ring * ring;
const offset = n - maxInRing;
let x, y;
if (n <= maxInRing - 2 * ring) {
x = offset + 3 * ring;
y = ring;
} else if (n <= maxInRing) {
x = ring;
y = -offset - ring;
} else if (n <= maxInRing + 2 * ring) {
x = ring - offset;
y = -ring;
} else {
x = -ring;
y = offset - 3 * ring;
}
let sum = adj.reduce(
(acc, [dx, dy]) => acc + (grid[`${x + dx},${y + dy}`] || 0),
0
);
if (sum > target) {
return sum;
}
grid[`${x},${y}`] = sum;
n++;
}
}