← All challenges

Jump Game (Reachability)

Grid / Path (Advanced) ★★☆☆

Determine whether a robot starting at A1 can reach the bottom-right cell of a 5×5 grid, where each cell's value is the exact jump distance available from that cell (right or down only).

A1:E5 is a 5×5 board. The robot starts at A1. Each cell’s value is the exact jump distance available from that cell — 3 means the robot can jump exactly 3 cells right or exactly 3 cells down, no shorter and no longer. A 0 means the robot is stuck (unless it’s already at the goal).

Return TRUE if there exists any sequence of valid jumps that lands exactly on E5 (bottom-right), FALSE otherwise.

Strategically placed 0s block the obvious routes, so the right path is not the path that maximises any single step — the formula has to explore both branches at every cell.

Input

Range A1:E5

ABCDE
1 12032
2 20111
3 23201
4 33021
5 10110
Hint

Recursive LAMBDA. From each cell, try jumping exactly cur cells down and exactly cur cells right; OR the two recursive results. Base cases: out-of-bounds → FALSE, cur=0 (and not at goal) → FALSE, at goal → TRUE.

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,
        OR(me(me, ro+cur, co), me(me, ro, co+cur))
      )))
    )
  ),
  fx(fx, 1, 1)
)