Exercise 5 - Random Walk

Assume that a walker is able to take steps length unity over a 2d-box as shown in Figure. The walker begins at the origin (0,0) and each step is choosen at random to be either to the right, left, top or bottom each with probability 1/4.

Write a program to calculate 'Average Number of Steps' for the walker to be outside of the region. (if a=3)

                       y
                       ^
                       |
                      a|
           +---+---+---+---+---+---+
           |   |   |   |   |   |   |
           |   |   |   |   |   |   |
           +---+---+---+---+---+---+
           |   |   |   |   |   |   |
           |   |   |   |   |   |   |
           +---+---+---+---+---+---+
           |   |   |   ^   |   |   |
        -a |   |   |   |   |   |   | a
  ---------+---+---+<--o-->+---+---+---------> x
           |   |   |   |   |   |   |
           |   |   |   V   |   |   |
           +---+---+---+---+---+---+
           |   |   |   |   |   |   |
           |   |   |   |   |   |   |
           +---+---+---+---+---+---+
           |   |   |   |   |   |   |
           |   |   |   |   |   |   |
           +---+---+---+---+---+---+
                     -a|
                       |