Surrounded Regions, traced one call at a time

Work from the edge inwards. Phase 1: every edge 'O' starts a dfs that marks its whole region 'T' (safe, it can reach the edge). Phase 2: one sweep turns every 'O' still unmarked into 'X' (captured) and every 'T' back into 'O'.

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Recursion tree

One subtree per edge 'O' · hover a call to find its cell

not called yet running now paused, waiting on a child marked safe ✕ = returned at once: out, 'X' or already 'T'

Call stack

Top frame runs; the rest are paused

Board

Edge cells have a thick outline; the outer ring is off the board

Xwall Oopen, not decided yet Tsafe (joined to the edge) Xcaptured edge cell

Keyboard: ← → step, Space play or pause. Boards up to 7×7. Starting from the edge means each safe region is searched once; testing every interior region on its own would mean searching it all the way out before knowing whether to capture it.