Max Coins with One Turn
Maximum coins collected from A1 to F6, moving only right at first and only down after one allowed turn — once you turn down, you cannot turn back.
A1:F6 is a 6×6 grid of coin piles. A collector starts at A1, moves through
the grid, and ends at F6. The catch: the collector can only move right
first, and once they make a single right-to-down turn, they can no
longer turn back — every remaining move must be down.
So a valid trajectory is: zero or more rights, exactly one downturn, zero or more downs. The collector picks up the coins in every cell they pass through. Output the maximum total coins on any valid trajectory.
There are only 6 + 6 − 1 = 11 such L-shaped trajectories on a 6×6 grid, but they fan out across very different sums. The formula encodes the once-allowed turn as a boolean in the recursion: before turning, the call has both branches; after turning, only the down branch is legal.
Input
Range A1:F6
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | 30 | 5 | 8 | 1 | 20 | 15 |
| 2 | 6 | 23 | 4 | 24 | 21 | 29 |
| 3 | 12 | 26 | 29 | 3 | 8 | 9 |
| 4 | 2 | 11 | 20 | 6 | 30 | 18 |
| 5 | 22 | 24 | 30 | 14 | 23 | 29 |
| 6 | 2 | 19 | 29 | 1 | 19 | 9 |
Hint
Branching recursion with a boolean `turned` argument. Before the turn, the next move can be either right (still not turned) or down (now turned). After the turn, only down is legal.
Solution
=LET(
tbl, A1:F6,
ros, ROWS(tbl),
cols, COLUMNS(tbl),
fx, LAMBDA(me, ro, co, turned,
IF(OR(ro>ros, co>cols),
0,
LET(
cur, INDEX(tbl, ro, co),
IF(AND(ro=ros, co=cols),
cur,
cur + IF(turned,
me(me, ro+1, co, TRUE),
MAX(me(me, ro, co+1, FALSE), me(me, ro+1, co, TRUE))
)
)
)
)
),
fx(fx, 1, 1, FALSE)
)