size × size, with rows and columns numbered from zero. A knight stands at (row, col) and is about to make exactly moves moves.
On each move the knight picks one of its eight directions (two cells one way and one cell sideways) uniformly at random, even if that move takes it off the board. Once the knight leaves the board, the walk is over and it never comes back.
Return the probability that the knight is still on the board after all the moves. Answers within 10⁻⁶ are accepted.size=4, moves=1, row=1, col=1 → 0.5
From (1, 1) on a 4×4 board the moves to (3, 0), (3, 2), (0, 3) and (2, 3) stay on the board, 4 out of 8, so the probability is 0.5.
size=2, moves=1, row=0, col=0 → 0
On a 2×2 board every knight move leaves the board.
size=6, moves=0, row=5, col=2 → 1
No moves are made, so the knight is still on the board: probability 1.
size ≤ 25moves ≤ 100row, col < sizesize=4, moves=1, row=1, col=1
0.5
Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.