MathsReadCompetitive mathematics
Algorithmic puzzle · integer answermedium50 min

Box-constrained returning walks

Exact Enumeration

A walker starts at (0,0). At each of 8 steps it moves one unit up, down, left, or right. How many ordered step sequences return to (0,0) after step 8 while NEVER leaving the box -2<=x<=2, -2<=y<=2?

Solve using mathematics, algorithms, or your own code offline. Submit only the final integer here—no program, expression, graph, or written proof.

Check your answer without signing in. Sign in to save your progress.

Accepted format: a whole number such as 42 or 123456789. No commas, formulas, or source code.

How to approach this problem

Maintain a map from position to number of walks after each step. Extend in four directions and reject coordinates outside the box immediately, even if the walk could return later.

Worked example with different values

In the box with coordinates from −1 to 1 on both axes, exactly four two-step walks return to the origin: each direction followed by its opposite.

Apply the same reasoning to the challenge. This example is a separate practice problem.

Learn the technique: Number theory: divisors, gcd and modular arithmetic

Report a question or explanation issue

Back to problems →