Jump Game with All Hops
Reachability on a 5×5 grid where each cell's value is the MAXIMUM jump distance — any shorter hop (1..max) is also legal. Right or down only.
A1:E5 is a 5×5 grid. The robot starts at A1. Each cell’s value is the
maximum jump distance from that cell — 3 means the robot may hop 1, 2,
or 3 cells right, or 1, 2, or 3 cells down. A 0 means the robot is
stuck (unless already at the goal).
Return TRUE if any sequence of valid jumps lands on E5 (bottom-right),
FALSE otherwise.
This is the more permissive cousin of the exact-jump variant. The formula trick is the inner REDUCE: at each cell, fold over all hop lengths 1..cur and OR the recursive reachability results, in each direction. (Side note: the exact-jump formula on this same grid returns FALSE — the smaller hops matter here.)
Input
Range A1:E5
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | 1 | 3 | 1 | 2 | 1 |
| 2 | 2 | 2 | 0 | 3 | 2 |
| 3 | 1 | 0 | 2 | 1 | 2 |
| 4 | 2 | 3 | 1 | 0 | 2 |
| 5 | 2 | 3 | 1 | 3 | 0 |
Hint
Like the exact-jump version, but at each cell try every hop length from 1 to cur. Use REDUCE over SEQUENCE(cur,,1) to OR together the results across all hop lengths in each direction.
Solution
=LET(
tbl, A1:E5,
ros, ROWS(tbl),
cols, COLUMNS(tbl),
fx, LAMBDA(me, ro, co,
LET(
cur, INDEX(tbl, ro, co),
IF(OR(ro>ros, co>cols), FALSE,
IF(cur=0, FALSE,
IF(AND(ro=ros, co=cols), TRUE,
LET(
down, REDUCE(FALSE, SEQUENCE(cur,,1), LAMBDA(s, c, OR(s, me(me, ro+c, co)))),
right, REDUCE(FALSE, SEQUENCE(cur,,1), LAMBDA(s, c, OR(s, me(me, ro, co+c)))),
OR(down, right)
)
)))
)
),
fx(fx, 1, 1)
)