Computer Modeling of a Random Walk

My son Dirk is interested in math and now that he is doing Calculus, it's a challenge for me to "keep up" since it's been 30 years since I took those classes. But he mentioned Random Walks the other day, which spurred me to whip up some computer code to simulate 'em. I figure I can do the computer modeling and he can do the theoretical analysis! ;-)

Some info about Random Walks at Wikipedia and Wolfram ... but in a nutshell, you start out from the origin, and take one step in a random direction ... and then another, and so on - think of a drunk person stumbling about. Note that you are NOT restricted to two dimensions. Turns out Random Walks are applicable to all sorts of real world things and you can do all sorts of statistical analysis on them.

On the right side of the page is the "guts" of the quick-n-dirty Perl program I wrote to simulate a SINGLE random walk in various dimensions and steps. What is more "interesting" is to then iterate over that for ALL possible routes. This is obviously generates a LOT more output plus is much more computations!

  Output from a SINGLE Random Walk
Steps D1         D2         D3         D4 (Dimensions)
1 d1s1 d2s1 d3s1 d4s1
2 d1s2 d2s2 d3s2 d4s2
3 d1s3 d2s3 d3s3 d4s3
4 d1s4 d2s4 d3s4 d4s4
5 d1s5 d2s5 d3s5 d4s5

 
  Output from ALL routes of a Random Walk
  Iterations is (2*Dimensions)**Steps - gets LARGE fast!
Steps D1         D2         D3         D4 (Dimensions)
1 d1s1 d2s1 d3s1 d4s1
2 d1s2 d2s2 d3s2 d4s2
3 d1s3 d2s3 d3s3 d4s3
4 d1s4 d2s4 d3s4 d4s4
5 d1s5 d2s5 d3s5 d4s5
  Only summary information for runs with steps > 3



Complete output from all 64 routes of a 2-D 3-Step random walk
./random-walk.pl -benchmark -iterate -show_all -dimensions=2 -steps=3   
Parameters are 2 dimensions (which has 4 directions) and 3 steps
Running 64 iterations - this can take a while!

for iteration 1 the directions are: 1 1 1 
Step   Direction       D1   D2 
   1           1       -1    0
   2           1       -2    0
   3           1       -3    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 2 the directions are: 1 1 2 
Step   Direction       D1   D2 
   1           1       -1    0
   2           1       -2    0
   3           2       -1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 3 the directions are: 1 1 3 
Step   Direction       D1   D2 
   1           1       -1    0
   2           1       -2    0
   3           3       -2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 4 the directions are: 1 1 4 
Step   Direction       D1   D2 
   1           1       -1    0
   2           1       -2    0
   3           4       -2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 5 the directions are: 1 2 1 
Step   Direction       D1   D2 
   1           1       -1    0
   2           2        0    0
   3           1       -1    0
Coordinates stepped on are: 1-1-2

for iteration 6 the directions are: 1 2 2 
Step   Direction       D1   D2 
   1           1       -1    0
   2           2        0    0
   3           2        1    0
Coordinates stepped on are: 1-1-1

for iteration 7 the directions are: 1 2 3 
Step   Direction       D1   D2 
   1           1       -1    0
   2           2        0    0
   3           3        0   -1
Coordinates stepped on are: 1-1-1

for iteration 8 the directions are: 1 2 4 
Step   Direction       D1   D2 
   1           1       -1    0
   2           2        0    0
   3           4        0    1
Coordinates stepped on are: 1-1-1

for iteration 9 the directions are: 1 3 1 
Step   Direction       D1   D2 
   1           1       -1    0
   2           3       -1   -1
   3           1       -2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 10 the directions are: 1 3 2 
Step   Direction       D1   D2 
   1           1       -1    0
   2           3       -1   -1
   3           2        0   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 11 the directions are: 1 3 3 
Step   Direction       D1   D2 
   1           1       -1    0
   2           3       -1   -1
   3           3       -1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 12 the directions are: 1 3 4 
Step   Direction       D1   D2 
   1           1       -1    0
   2           3       -1   -1
   3           4       -1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 13 the directions are: 1 4 1 
Step   Direction       D1   D2 
   1           1       -1    0
   2           4       -1    1
   3           1       -2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 14 the directions are: 1 4 2 
Step   Direction       D1   D2 
   1           1       -1    0
   2           4       -1    1
   3           2        0    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 15 the directions are: 1 4 3 
Step   Direction       D1   D2 
   1           1       -1    0
   2           4       -1    1
   3           3       -1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 16 the directions are: 1 4 4 
Step   Direction       D1   D2 
   1           1       -1    0
   2           4       -1    1
   3           4       -1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 17 the directions are: 2 1 1 
Step   Direction       D1   D2 
   1           2        1    0
   2           1        0    0
   3           1       -1    0
Coordinates stepped on are: 1-1-1

for iteration 18 the directions are: 2 1 2 
Step   Direction       D1   D2 
   1           2        1    0
   2           1        0    0
   3           2        1    0
Coordinates stepped on are: 1-1-2

for iteration 19 the directions are: 2 1 3 
Step   Direction       D1   D2 
   1           2        1    0
   2           1        0    0
   3           3        0   -1
Coordinates stepped on are: 1-1-1

for iteration 20 the directions are: 2 1 4 
Step   Direction       D1   D2 
   1           2        1    0
   2           1        0    0
   3           4        0    1
Coordinates stepped on are: 1-1-1

for iteration 21 the directions are: 2 2 1 
Step   Direction       D1   D2 
   1           2        1    0
   2           2        2    0
   3           1        1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 22 the directions are: 2 2 2 
Step   Direction       D1   D2 
   1           2        1    0
   2           2        2    0
   3           2        3    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 23 the directions are: 2 2 3 
Step   Direction       D1   D2 
   1           2        1    0
   2           2        2    0
   3           3        2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 24 the directions are: 2 2 4 
Step   Direction       D1   D2 
   1           2        1    0
   2           2        2    0
   3           4        2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 25 the directions are: 2 3 1 
Step   Direction       D1   D2 
   1           2        1    0
   2           3        1   -1
   3           1        0   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 26 the directions are: 2 3 2 
Step   Direction       D1   D2 
   1           2        1    0
   2           3        1   -1
   3           2        2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 27 the directions are: 2 3 3 
Step   Direction       D1   D2 
   1           2        1    0
   2           3        1   -1
   3           3        1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 28 the directions are: 2 3 4 
Step   Direction       D1   D2 
   1           2        1    0
   2           3        1   -1
   3           4        1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 29 the directions are: 2 4 1 
Step   Direction       D1   D2 
   1           2        1    0
   2           4        1    1
   3           1        0    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 30 the directions are: 2 4 2 
Step   Direction       D1   D2 
   1           2        1    0
   2           4        1    1
   3           2        2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 31 the directions are: 2 4 3 
Step   Direction       D1   D2 
   1           2        1    0
   2           4        1    1
   3           3        1    0
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 32 the directions are: 2 4 4 
Step   Direction       D1   D2 
   1           2        1    0
   2           4        1    1
   3           4        1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 33 the directions are: 3 1 1 
Step   Direction       D1   D2 
   1           3        0   -1
   2           1       -1   -1
   3           1       -2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 34 the directions are: 3 1 2 
Step   Direction       D1   D2 
   1           3        0   -1
   2           1       -1   -1
   3           2        0   -1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 35 the directions are: 3 1 3 
Step   Direction       D1   D2 
   1           3        0   -1
   2           1       -1   -1
   3           3       -1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 36 the directions are: 3 1 4 
Step   Direction       D1   D2 
   1           3        0   -1
   2           1       -1   -1
   3           4       -1    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 37 the directions are: 3 2 1 
Step   Direction       D1   D2 
   1           3        0   -1
   2           2        1   -1
   3           1        0   -1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 38 the directions are: 3 2 2 
Step   Direction       D1   D2 
   1           3        0   -1
   2           2        1   -1
   3           2        2   -1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 39 the directions are: 3 2 3 
Step   Direction       D1   D2 
   1           3        0   -1
   2           2        1   -1
   3           3        1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 40 the directions are: 3 2 4 
Step   Direction       D1   D2 
   1           3        0   -1
   2           2        1   -1
   3           4        1    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 41 the directions are: 3 3 1 
Step   Direction       D1   D2 
   1           3        0   -1
   2           3        0   -2
   3           1       -1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 42 the directions are: 3 3 2 
Step   Direction       D1   D2 
   1           3        0   -1
   2           3        0   -2
   3           2        1   -2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 43 the directions are: 3 3 3 
Step   Direction       D1   D2 
   1           3        0   -1
   2           3        0   -2
   3           3        0   -3
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 44 the directions are: 3 3 4 
Step   Direction       D1   D2 
   1           3        0   -1
   2           3        0   -2
   3           4        0   -1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 45 the directions are: 3 4 1 
Step   Direction       D1   D2 
   1           3        0   -1
   2           4        0    0
   3           1       -1    0
Coordinates stepped on are: 1-1-1

for iteration 46 the directions are: 3 4 2 
Step   Direction       D1   D2 
   1           3        0   -1
   2           4        0    0
   3           2        1    0
Coordinates stepped on are: 1-1-1

for iteration 47 the directions are: 3 4 3 
Step   Direction       D1   D2 
   1           3        0   -1
   2           4        0    0
   3           3        0   -1
Coordinates stepped on are: 1-1-2

for iteration 48 the directions are: 3 4 4 
Step   Direction       D1   D2 
   1           3        0   -1
   2           4        0    0
   3           4        0    1
Coordinates stepped on are: 1-1-1

for iteration 49 the directions are: 4 1 1 
Step   Direction       D1   D2 
   1           4        0    1
   2           1       -1    1
   3           1       -2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 50 the directions are: 4 1 2 
Step   Direction       D1   D2 
   1           4        0    1
   2           1       -1    1
   3           2        0    1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 51 the directions are: 4 1 3 
Step   Direction       D1   D2 
   1           4        0    1
   2           1       -1    1
   3           3       -1    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 52 the directions are: 4 1 4 
Step   Direction       D1   D2 
   1           4        0    1
   2           1       -1    1
   3           4       -1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 53 the directions are: 4 2 1 
Step   Direction       D1   D2 
   1           4        0    1
   2           2        1    1
   3           1        0    1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 54 the directions are: 4 2 2 
Step   Direction       D1   D2 
   1           4        0    1
   2           2        1    1
   3           2        2    1
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 55 the directions are: 4 2 3 
Step   Direction       D1   D2 
   1           4        0    1
   2           2        1    1
   3           3        1    0
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 56 the directions are: 4 2 4 
Step   Direction       D1   D2 
   1           4        0    1
   2           2        1    1
   3           4        1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 57 the directions are: 4 3 1 
Step   Direction       D1   D2 
   1           4        0    1
   2           3        0    0
   3           1       -1    0
Coordinates stepped on are: 1-1-1

for iteration 58 the directions are: 4 3 2 
Step   Direction       D1   D2 
   1           4        0    1
   2           3        0    0
   3           2        1    0
Coordinates stepped on are: 1-1-1

for iteration 59 the directions are: 4 3 3 
Step   Direction       D1   D2 
   1           4        0    1
   2           3        0    0
   3           3        0   -1
Coordinates stepped on are: 1-1-1

for iteration 60 the directions are: 4 3 4 
Step   Direction       D1   D2 
   1           4        0    1
   2           3        0    0
   3           4        0    1
Coordinates stepped on are: 1-1-2

for iteration 61 the directions are: 4 4 1 
Step   Direction       D1   D2 
   1           4        0    1
   2           4        0    2
   3           1       -1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 62 the directions are: 4 4 2 
Step   Direction       D1   D2 
   1           4        0    1
   2           4        0    2
   3           2        1    2
Coordinates stepped on are: 1-1-1   Never returned to origin

for iteration 63 the directions are: 4 4 3 
Step   Direction       D1   D2 
   1           4        0    1
   2           4        0    2
   3           3        0    1
Coordinates stepped on are: 1-1-2   Never returned to origin

for iteration 64 the directions are: 4 4 4 
Step   Direction       D1   D2 
   1           4        0    1
   2           4        0    2
   3           4        0    3
Coordinates stepped on are: 1-1-1   Never returned to origin


Frequency    Stepped Ons
       48    1-1-1
       16    1-1-2
       64    Total Routes
       16    Returned to origin which is 25%


Frequency    Coordinate
       25    (1,0)
       25    (0,1)
       25    (0,-1)
       25    (-1,0)
       16    (0,0)
        8    (1,-1)
        8    (-1,1)
        8    (-1,-1)
        8    (1,1)
        4    (-2,0)
        4    (0,2)
        4    (2,0)
        4    (0,-2)
        3    (-2,-1)
        3    (-2,1)
        3    (1,-2)
        3    (1,2)
        3    (-1,-2)
        3    (2,-1)
        3    (-1,2)
        3    (2,1)
        1    (3,0)
        1    (-3,0)
        1    (0,-3)
        1    (0,3)


Direction    Frequency
        1           48
        2           48
        3           48
        4           48


 Distance    Frequency    Cumulative
        0           16    
        1          116    50%
        2          164    
        3          192    100%


For Random Walk of 2 dimensions and 3 steps,
distance at which N percent of coordinates are contained
        1           10%
        1           50%
        3           90%
        3          100%


Timing Data: 0.003 seconds to run



Summary output from all 1,048,576 routes of a 2-D 10-Step random walk
./random-walk.pl -benchmark -iterate -dimensions=2 -steps=10
   -show_coords_freq -show_directions -show_distances -show_stepped_ons
Parameters are 2 dimensions (which has 4 directions) and 10 steps
Running 1048576 iterations - this can take a while!

Frequency    Stepped Ons
    65072    1-1-1-1-1-1-1-1-1-1
    29584    1-1-1-1-1-1-1-1-1-2
    25760    1-1-1-1-1-1-1-1-2-2
    23664    1-1-2-1-1-1-1-1-1-1
    19872    1-1-1-1-2-1-1-1-1-1
    19280    1-1-1-1-1-1-1-2-2-1
    18592    1-1-1-1-1-1-1-1-2-1
    18448    1-1-1-1-1-1-2-2-1-1
    18384    1-1-1-1-1-2-2-1-1-1
    17520    1-1-1-1-2-2-1-1-1-1
    17504    1-1-1-1-1-1-1-2-1-1
    17408    1-1-1-1-1-1-2-1-1-1
    17376    1-1-1-2-2-1-1-1-1-1
    16288    1-1-1-1-1-2-1-1-1-1
    16160    1-1-1-2-1-1-1-1-1-1
    11088    1-1-2-1-1-1-1-1-1-2
    10112    1-1-1-1-1-1-2-1-1-2
     9568    1-1-1-1-2-1-1-1-1-2
     8864    1-1-1-1-1-1-1-2-2-3
     8688    1-1-2-2-1-1-1-1-1-1
     8352    1-1-2-1-1-1-1-1-2-2
     7840    1-1-1-1-1-1-2-1-3-2
     7408    1-1-1-1-1-2-2-1-1-2
     7360    1-1-2-1-1-2-1-1-1-1
     7312    1-1-1-1-1-1-1-2-2-2
     7264    1-1-1-2-2-1-1-1-1-2
     6880    1-1-2-1-1-1-1-2-1-1
     6848    1-1-1-1-2-1-3-2-1-1
     6768    1-1-1-1-1-1-2-2-1-3
     6624    1-1-1-2-1-1-1-1-1-2
     6544    1-1-1-1-2-2-1-1-1-2
     6432    1-1-1-2-1-3-2-1-1-1
     6400    1-1-1-1-1-2-1-3-2-1
     6368    1-1-1-1-2-1-1-2-1-1
     6336    1-1-1-1-2-1-1-1-2-2
     6304    1-1-1-1-1-1-1-2-1-3
     6240    1-1-2-1-3-2-1-1-1-1
     6176    1-1-2-1-1-1-1-1-2-1
     6096    1-1-2-1-1-1-1-2-2-1
     6080    1-1-1-1-1-2-1-1-2-1
     5920    1-1-1-1-1-2-1-1-1-2
     5824    1-1-1-2-1-1-2-1-1-1
     5728    1-1-2-1-3-1-1-1-1-1
     5504    1-1-1-2-1-1-1-1-2-2
     5488    1-1-2-1-1-1-2-2-1-1
     5344    1-1-1-1-1-1-2-2-3-1
     5312    1-1-1-1-1-1-2-2-2-1
     5216    1-1-2-1-1-1-2-1-1-1
     5184    1-1-1-1-2-2-3-1-1-1
     5056    1-1-1-2-1-1-1-1-2-1
     4960    1-1-1-1-2-2-1-1-2-1
     4928    1-1-1-1-1-2-2-3-1-1
     4800    1-1-1-2-2-1-1-1-2-2
     4672    1-1-1-1-2-1-1-1-2-1
     4656    1-1-1-1-2-2-2-1-1-1
     4608    1-1-1-2-2-1-1-1-2-1
     4320    1-1-1-1-1-2-1-1-2-2
     4288    1-1-1-2-2-3-1-1-1-1
     4256    1-1-1-1-1-1-2-2-3-2
     4160    1-1-1-2-2-1-3-1-1-1
     4160    1-1-1-2-2-1-1-2-1-1
     4160    1-1-1-1-2-1-1-2-2-1
     4128    1-1-1-2-1-1-1-2-2-1
     3824    1-1-1-1-1-2-2-1-3-2
     3712    1-1-1-1-1-2-2-1-3-1
     3632    1-1-2-2-1-1-1-1-1-2
     3632    1-1-2-1-1-2-2-1-1-1
     3520    1-1-1-2-1-1-1-2-1-1
     3504    1-1-1-1-2-2-1-3-2-1
     3424    1-1-1-1-1-2-2-2-1-1
     3408    1-1-1-1-1-2-2-3-2-1
     3296    1-1-1-1-1-2-1-1-2-3
     3264    1-1-1-1-2-2-1-3-1-1
     3200    1-1-1-1-1-1-2-2-3-3
     3184    1-1-1-1-1-1-2-2-2-2
     3120    1-1-2-2-3-1-1-1-1-1
     3120    1-1-1-1-2-2-1-1-2-2
     3104    1-1-2-1-1-1-2-1-1-2
     2912    1-1-1-2-1-1-2-2-1-1
     2848    1-1-2-1-3-1-1-1-1-2
     2832    1-1-1-1-1-1-2-2-2-3
     2784    1-1-2-1-1-1-1-2-2-3
     2784    1-1-1-2-1-1-1-2-2-3
     2752    1-1-2-1-1-2-1-1-1-2
     2752    1-1-1-1-2-1-1-2-3-2
     2688    1-1-1-2-1-1-2-1-1-2
     2656    1-1-2-1-1-1-2-1-3-2
     2656    1-1-2-2-1-1-1-1-2-2
     2624    1-1-1-1-2-1-3-2-1-3
     2608    1-1-1-1-2-2-1-1-2-3
     2592    1-1-2-1-1-2-3-1-1-1
     2528    1-1-1-2-2-1-1-2-2-1
     2528    1-1-1-1-1-2-1-3-2-4
     2512    1-1-1-1-1-2-2-1-3-3
     2512    1-1-1-1-1-2-2-3-3-1
     2496    1-1-2-1-1-1-1-2-1-3
     2464    1-1-2-1-1-1-2-2-3-1
     2464    1-1-2-1-3-2-1-1-1-2
     2400    1-1-1-1-2-1-1-2-1-3
     2368    1-1-1-1-2-2-3-1-1-2
     2336    1-1-1-1-2-1-3-1-1-1
     2336    1-1-2-2-1-1-1-1-2-1
     2320    1-1-1-1-2-2-3-3-1-1
     2320    1-1-1-1-2-2-3-2-1-1
     2272    1-1-1-2-2-3-2-1-1-1
     2272    1-1-1-2-2-3-3-1-1-1
     2272    1-1-1-2-2-1-3-2-1-1
     2256    1-1-2-1-1-1-1-2-2-2
     2240    1-1-2-1-1-2-1-1-2-1
     2240    1-1-1-2-1-1-2-3-2-1
     2208    1-1-2-1-3-1-4-2-1-1
     2208    1-1-1-2-1-3-2-1-1-2
     2176    1-1-2-1-3-1-1-2-1-1
     2144    1-1-1-1-1-1-2-1-3-1
     2144    1-1-2-2-1-3-1-1-1-1
     2112    1-1-1-1-2-1-3-2-4-2
     2080    1-1-2-2-1-1-1-2-1-1
     2080    1-1-2-2-1-1-2-1-1-1
     2064    1-1-2-1-1-1-2-2-1-3
     2016    1-1-1-2-1-3-1-1-1-1
     1984    1-1-1-2-2-1-3-1-1-2
     1968    1-1-1-1-1-2-2-2-2-1
     1936    1-1-2-2-1-1-1-2-2-1
     1920    1-1-2-1-1-2-1-3-2-1
     1904    1-1-1-1-2-2-2-1-1-2
     1888    1-1-1-1-1-2-1-3-1-1
     1856    1-1-1-1-1-1-2-2-1-2
     1728    1-1-2-1-3-1-1-1-2-2
     1728    1-1-1-2-2-1-1-2-1-3
     1728    1-1-1-2-1-3-2-4-2-1
     1728    1-1-1-1-1-2-2-3-1-4
     1728    1-1-1-1-2-1-1-2-2-3
     1728    1-1-1-2-1-3-2-1-3-1
     1712    1-1-2-1-1-1-2-2-3-2
     1664    1-1-1-1-1-1-2-1-2-2
     1664    1-1-1-2-1-1-2-1-3-2
     1632    1-1-1-1-2-2-1-3-3-1
     1632    1-1-1-1-2-1-3-1-1-2
     1600    1-1-1-2-2-1-1-2-3-1
     1600    1-1-2-1-3-2-1-3-1-1
     1600    1-1-1-2-2-1-3-3-1-1
     1600    1-1-1-2-2-1-1-2-3-3
     1472    1-1-1-2-2-3-1-1-1-2
     1472    1-1-2-1-3-2-1-1-2-1
     1472    1-1-2-1-3-2-4-1-1-1
     1456    1-1-2-1-1-2-2-1-1-2
     1440    1-1-1-1-1-2-2-3-2-4
     1408    1-1-1-2-2-3-1-1-2-1
     1408    1-1-2-1-1-2-1-1-2-2
     1408    1-1-1-1-1-1-1-2-1-2
     1408    1-1-1-1-2-1-3-1-4-2
     1408    1-1-1-1-2-2-3-1-4-2
     1392    1-1-2-1-1-1-2-2-3-3
     1376    1-1-1-1-1-2-2-1-2-2
     1376    1-1-1-1-2-1-1-2-3-3
     1376    1-1-1-1-1-2-2-1-2-1
     1376    1-1-1-1-2-1-1-2-3-1
     1376    1-1-1-1-2-2-2-3-1-1
     1344    1-1-1-2-1-1-1-2-1-3
     1328    1-1-2-2-3-1-1-1-1-2
     1328    1-1-2-1-1-2-3-2-1-1
     1312    1-1-1-1-1-2-2-2-1-3
     1312    1-1-1-1-1-2-2-2-3-1
     1312    1-1-1-1-1-2-2-2-3-3
     1296    1-1-1-1-2-2-1-3-2-4
     1264    1-1-2-2-1-1-1-2-2-3
     1248    1-1-1-1-2-1-3-2-2-1
     1216    1-1-2-1-3-1-1-1-2-1
     1216    1-1-2-1-1-2-3-1-1-2
     1216    1-1-2-1-1-2-1-1-2-3
     1216    1-1-2-1-1-1-3-2-1-1
     1184    1-1-1-2-1-1-2-3-1-1
     1184    1-1-1-2-2-1-1-2-2-3
     1184    1-1-1-1-1-2-1-3-2-2
     1168    1-1-1-1-1-2-2-2-2-3
     1152    1-1-1-2-2-1-3-1-4-2
     1152    1-1-1-2-2-3-1-4-2-1
     1152    1-1-1-2-1-3-1-4-2-1
     1152    1-1-1-1-2-2-1-3-1-4
     1136    1-1-2-2-1-1-2-2-1-1
     1136    1-1-2-2-1-3-2-1-1-1
     1136    1-1-2-2-3-3-1-1-1-1
     1136    1-1-2-2-1-3-3-1-1-1
     1072    1-1-1-1-2-2-2-3-3-1
     1056    1-1-1-1-2-1-3-2-4-3
     1056    1-1-1-1-1-2-2-3-3-4
     1056    1-1-1-1-2-1-3-2-4-1
     1056    1-1-1-2-1-1-2-2-1-3
     1024    1-1-1-1-2-1-1-2-2-2
     1024    1-1-1-1-1-2-2-1-1-3
     1024    1-1-1-2-2-1-2-1-1-1
     1024    1-1-1-1-2-1-2-1-1-1
     1024    1-1-1-1-2-1-3-2-1-2
     1024    1-1-1-1-2-1-1-1-3-2
      992    1-1-2-1-1-2-1-3-1-1
      992    1-1-1-1-2-2-2-1-3-1
      992    1-1-2-1-3-1-1-2-2-1
      992    1-1-2-1-1-2-3-3-1-1
      992    1-1-2-1-1-2-2-3-1-1
      992    1-1-2-2-1-1-2-1-1-2
      976    1-1-1-1-2-2-2-1-3-2
      960    1-1-1-2-1-3-1-1-2-1
      944    1-1-1-1-2-2-3-2-1-3
      928    1-1-2-1-3-2-1-1-2-2
      928    1-1-1-2-2-1-3-2-1-3
      912    1-1-1-1-1-2-2-3-2-2
      896    1-1-1-1-1-2-1-2-2-1
      864    1-1-1-2-1-3-2-1-3-2
      864    1-1-2-1-3-1-4-2-1-3
      864    1-1-2-1-1-2-2-1-3-1
      864    1-1-1-2-1-3-2-4-3-1
      864    1-1-1-2-1-3-2-1-3-4
      864    1-1-2-2-1-1-1-2-1-3
      864    1-1-1-2-1-3-2-4-1-1
      832    1-1-1-2-1-1-1-1-2-3
      832    1-1-1-1-2-1-1-2-1-2
      832    1-1-1-2-1-1-2-3-3-1
      832    1-1-1-1-2-2-1-1-1-3
      832    1-1-2-1-3-1-1-2-1-3
      832    1-1-1-2-1-1-2-3-2-4
      832    1-1-2-1-3-1-1-2-4-2
      832    1-1-1-2-1-1-2-1-3-1
      832    1-1-1-2-1-1-2-1-3-3
      832    1-1-1-2-1-1-2-2-3-3
      832    1-1-1-2-1-1-2-2-3-1
      816    1-1-2-1-1-2-2-3-3-1
      816    1-1-1-1-2-2-3-3-1-4
      816    1-1-1-1-2-2-1-3-3-4
      816    1-1-1-1-2-2-1-3-3-2
      800    1-1-2-1-3-2-1-1-2-3
      800    1-1-2-1-1-1-2-1-3-1
      800    1-1-2-2-3-1-1-1-2-2
      800    1-1-2-1-3-2-4-3-1-1
      800    1-1-2-2-1-1-2-3-1-1
      800    1-1-2-1-3-2-4-2-1-1
      800    1-1-2-1-3-2-1-3-2-1
      800    1-1-2-2-3-1-1-2-1-1
      800    1-1-1-2-2-1-3-3-2-1
      800    1-1-1-2-2-3-3-1-1-2
      800    1-1-1-2-2-3-2-1-1-2
      768    1-1-1-1-2-2-2-2-1-1
      768    1-1-1-1-2-2-1-1-3-2
      768    1-1-1-2-1-3-2-1-2-1
      768    1-1-1-1-1-1-2-1-2-1
      768    1-1-1-2-2-1-1-1-3-2
      736    1-1-2-2-3-1-1-1-2-1
      736    1-1-2-2-3-1-4-1-1-1
      736    1-1-2-2-1-3-1-1-1-2
      720    1-1-2-1-1-2-2-1-3-2
      704    1-1-1-1-2-2-3-1-4-3
      704    1-1-2-1-1-2-3-1-4-2
      704    1-1-2-1-1-2-1-3-3-1
      704    1-1-2-1-1-1-2-2-1-2
      704    1-1-2-1-1-2-1-3-2-4
      704    1-1-2-1-3-2-4-1-1-2
      704    1-1-1-1-2-2-3-2-4-1
      704    1-1-1-2-2-3-2-1-3-1
      704    1-1-1-1-2-2-3-3-4-1
      704    1-1-2-2-1-3-1-1-2-1
      704    1-1-1-2-2-3-1-1-2-4
      704    1-1-1-2-2-3-1-1-2-2
      704    1-1-1-1-2-2-3-2-4-3
      704    1-1-1-1-2-2-3-1-4-1
      704    1-1-1-1-2-1-2-2-1-1
      688    1-1-2-2-1-1-2-3-3-1
      672    1-1-2-1-3-1-4-1-1-1
      672    1-1-1-2-1-3-1-1-1-2
      672    1-1-2-1-1-1-1-2-3-1
      672    1-1-1-1-1-2-1-3-1-4
      656    1-1-1-1-1-2-2-3-3-2
      656    1-1-1-1-2-2-2-1-3-3
      640    1-1-1-1-1-2-1-2-2-3
      640    1-1-1-2-1-1-1-3-2-1
      640    1-1-1-2-2-1-1-3-2-1
      640    1-1-1-2-1-1-2-1-2-1
      640    1-1-2-2-1-1-2-1-3-2
      608    1-1-2-1-1-1-1-2-1-2
      592    1-1-1-1-2-2-3-2-2-1
      592    1-1-1-1-2-2-3-3-2-1
      576    1-1-1-2-2-1-3-3-4-1
      576    1-1-1-2-2-3-1-4-3-1
      576    1-1-2-1-3-1-4-2-5-2
      576    1-1-1-2-2-1-3-2-4-3
      576    1-1-1-2-2-1-3-1-4-3
      576    1-1-1-2-2-3-2-4-3-1
      576    1-1-1-2-2-1-3-1-4-1
      576    1-1-2-1-1-1-1-2-3-2
      576    1-1-2-1-3-2-1-3-1-4
      576    1-1-1-2-2-1-3-2-4-1
      576    1-1-2-1-3-2-1-3-4-1
      576    1-1-1-2-1-3-2-4-2-5
      576    1-1-1-2-2-3-1-4-1-1
      576    1-1-1-2-2-3-3-1-4-1
      576    1-1-2-2-1-3-1-4-2-1
      576    1-1-1-1-1-2-2-1-2-3
      576    1-1-1-1-2-2-1-2-1-1
      576    1-1-1-2-2-1-3-3-1-4
      576    1-1-1-2-2-3-2-4-1-1
      576    1-1-1-2-2-3-3-4-1-1
      544    1-1-1-1-2-1-3-2-2-3
      528    1-1-2-1-1-2-2-1-3-3
      528    1-1-2-1-1-2-3-2-1-3
      512    1-1-2-2-1-1-3-1-1-1
      512    1-1-1-2-1-1-2-2-2-3
      512    1-1-2-1-1-1-1-1-3-2
      512    1-1-1-1-2-1-2-1-1-2
      512    1-1-1-1-2-2-2-2-3-1
      512    1-1-1-2-1-1-2-2-2-1
      512    1-1-1-1-2-2-2-2-3-3
      480    1-1-1-1-2-2-2-3-3-4
      480    1-1-1-2-1-3-1-1-2-2
      480    1-1-2-1-3-1-4-1-1-2
      480    1-1-1-1-2-2-2-3-1-4
      480    1-1-1-2-1-3-1-1-2-4
      464    1-1-2-1-1-2-3-3-2-1
      464    1-1-2-2-1-1-2-2-1-3
      448    1-1-1-2-2-1-2-1-1-2
      448    1-1-1-1-2-2-1-2-2-1
      448    1-1-2-1-1-1-3-1-1-1
      448    1-1-1-2-2-1-1-1-2-3
      448    1-1-1-1-1-2-1-1-1-3
      448    1-1-2-1-1-1-3-2-1-3
      416    1-1-2-2-1-1-2-1-3-1
      416    1-1-2-1-3-1-1-2-4-3
      416    1-1-1-2-1-1-2-3-3-4
      416    1-1-1-2-1-1-2-3-1-4
      416    1-1-2-1-1-1-1-2-3-3
      416    1-1-2-1-3-1-1-2-4-1
      416    1-1-1-2-1-1-2-3-3-2
      416    1-1-2-1-3-1-1-2-2-3
      400    1-1-2-2-1-3-2-1-1-2
      400    1-1-2-2-3-1-4-2-1-1
      400    1-1-2-2-1-3-3-1-1-2
      400    1-1-2-2-3-1-1-2-2-1
      400    1-1-2-2-3-1-4-3-1-1
      400    1-1-2-2-3-3-1-1-1-2
      400    1-1-2-2-3-3-4-1-1-1
      384    1-1-1-2-2-1-1-3-1-1
      384    1-1-1-1-2-2-1-1-3-3
      384    1-1-1-1-1-2-1-2-1-1
      384    1-1-1-1-2-1-3-2-2-2
      384    1-1-1-1-2-2-3-1-1-3
      384    1-1-1-2-2-1-1-1-3-3
      384    1-1-1-2-2-1-2-3-1-1
      384    1-1-2-1-1-1-3-2-4-2
      384    1-1-2-1-3-1-4-2-1-2
      384    1-1-2-1-3-1-4-1-5-2
      384    1-1-1-2-1-3-1-4-2-5
      384    1-1-2-1-1-2-2-2-1-1
      384    1-1-2-1-1-2-1-2-1-1
      384    1-1-1-1-2-2-1-1-3-1
      384    1-1-1-1-2-1-2-2-3-1
      384    1-1-2-1-3-2-1-1-1-3
      384    1-1-1-1-2-2-1-3-2-2
      384    1-1-1-2-2-3-1-4-2-5
      384    1-1-1-1-2-1-2-1-3-2
      384    1-1-1-2-2-1-1-1-3-1
      384    1-1-1-2-2-1-2-2-1-1
      384    1-1-1-2-1-3-2-1-2-4
      384    1-1-2-1-3-2-4-1-5-2
      384    1-1-1-2-1-3-2-1-2-2
      384    1-1-1-1-2-1-2-2-3-2
      384    1-1-2-1-3-2-1-2-1-1
      368    1-1-1-1-2-2-3-2-2-3
      368    1-1-1-1-2-2-2-3-3-2
      352    1-1-1-1-2-2-3-3-4-4
      352    1-1-2-1-1-2-2-3-1-4
      352    1-1-1-2-2-3-2-1-3-4
      352    1-1-2-2-1-1-2-2-3-3
      352    1-1-2-1-1-2-3-1-4-1
      352    1-1-2-2-1-1-2-2-3-1
      352    1-1-1-1-2-2-3-3-4-2
      352    1-1-2-1-1-2-2-3-3-4
      352    1-1-2-2-1-3-1-1-2-2
      352    1-1-2-1-1-2-3-1-4-3
      352    1-1-2-1-1-2-3-3-1-4
      352    1-1-2-2-1-3-1-1-2-4
      352    1-1-2-1-1-2-3-3-4-1
      352    1-1-2-1-3-2-4-2-1-3
      352    1-1-2-1-1-2-3-2-4-3
      352    1-1-2-1-1-2-3-2-4-1
      352    1-1-2-1-1-2-1-3-1-4
      352    1-1-2-2-3-1-1-2-1-3
      352    1-1-2-2-1-1-2-1-3-3
      352    1-1-2-1-1-2-1-3-3-2
      352    1-1-1-2-2-3-2-1-3-2
      352    1-1-2-2-3-1-4-1-1-2
      352    1-1-2-2-1-3-2-1-3-1
      352    1-1-2-1-1-2-1-3-3-4
      320    1-1-2-2-1-1-1-1-2-3
      320    1-1-1-2-1-1-2-1-2-3
      320    1-1-2-1-1-2-1-1-3-2
      320    1-1-1-1-2-2-1-2-2-3
      320    1-1-1-2-2-1-1-1-1-3
      320    1-1-2-1-1-1-3-1-1-2
      320    1-1-1-2-1-1-2-1-2-2
      320    1-1-2-1-3-1-1-2-1-2
      288    1-1-2-1-3-2-1-3-2-4
      288    1-1-1-2-2-3-3-1-4-4
      288    1-1-1-2-2-3-3-1-4-2
      288    1-1-2-2-1-3-2-4-3-1
      288    1-1-2-2-1-3-2-4-1-1
      288    1-1-2-2-1-3-1-4-3-1
      288    1-1-1-2-2-1-3-3-4-2
      288    1-1-2-2-3-1-1-2-4-1
      288    1-1-2-2-1-3-3-4-1-1
      288    1-1-2-1-3-1-4-2-5-3
      288    1-1-1-2-1-3-2-4-1-5
      288    1-1-2-2-1-3-1-4-1-1
      288    1-1-2-2-1-1-2-3-3-4
      288    1-1-1-1-2-2-2-1-1-3
      288    1-1-1-2-2-1-3-3-2-4
      288    1-1-2-1-3-2-4-3-1-4
      288    1-1-2-2-1-3-3-1-4-1
      288    1-1-2-1-3-1-4-2-5-1
      288    1-1-2-1-3-2-1-3-4-4
      288    1-1-2-2-3-1-1-2-4-3
      288    1-1-1-2-2-3-3-4-4-1
      288    1-1-1-2-2-1-3-3-4-4
      288    1-1-1-2-1-3-2-4-3-5
      288    1-1-2-2-3-3-1-4-1-1
      288    1-1-2-2-3-3-1-1-2-1
      288    1-1-2-2-1-1-2-3-1-4
      288    1-1-1-2-2-3-3-4-2-1
      288    1-1-2-1-3-2-1-3-4-2
      256    1-1-1-1-2-2-3-1-2-1
      256    1-1-2-1-1-1-3-2-2-1
      256    1-1-2-1-3-1-1-2-2-2
      256    1-1-2-1-1-2-1-1-1-3
      256    1-1-1-2-2-1-3-1-1-3
      256    1-1-1-1-1-2-2-3-1-2
      256    1-1-1-2-2-1-1-3-3-1
      256    1-1-1-2-2-3-1-1-3-1
      256    1-1-1-2-1-1-1-3-2-4
      256    1-1-2-1-1-2-2-2-3-3
      256    1-1-1-2-2-1-2-3-3-1
      256    1-1-1-1-2-2-1-2-3-3
      256    1-1-2-1-1-2-2-2-3-1
      256    1-1-1-2-2-1-2-2-3-1
      256    1-1-2-2-1-1-1-3-2-1
      256    1-1-1-1-2-2-2-2-1-3
      256    1-1-1-2-1-1-2-3-2-2
      256    1-1-1-1-2-2-1-2-3-1
      256    1-1-2-1-3-1-1-1-4-2
      256    1-1-1-1-2-1-2-2-1-3
      256    1-1-1-1-2-1-2-2-3-3
      256    1-1-2-1-3-2-1-1-4-2
      256    1-1-1-2-2-1-3-1-2-1
      256    1-1-1-2-2-1-1-3-2-4
      256    1-1-2-1-1-1-3-1-4-2
      256    1-1-1-2-2-1-2-1-3-2
      256    1-1-1-2-2-1-2-2-3-3
      240    1-1-2-1-1-2-2-3-3-2
      240    1-1-1-1-2-2-3-3-2-4
      224    1-1-2-1-1-2-2-1-1-3
      224    1-1-2-2-1-1-3-1-1-2
      192    1-1-2-2-3-1-1-3-1-1
      192    1-1-1-2-1-1-2-1-1-3
      192    1-1-2-1-3-2-4-3-5-1
      192    1-1-2-1-3-2-4-1-5-3
      192    1-1-1-2-2-3-1-4-1-5
      192    1-1-2-2-1-3-1-4-2-5
      192    1-1-2-2-1-1-1-3-1-1
      192    1-1-2-1-1-1-3-2-4-1
      192    1-1-1-2-1-3-2-1-1-4
      192    1-1-2-2-1-1-3-3-1-1
      192    1-1-1-2-2-3-3-4-1-5
      192    1-1-2-1-3-2-4-2-5-1
      192    1-1-1-1-2-2-1-2-1-3
      192    1-1-1-2-2-3-2-4-3-5
      192    1-1-2-1-1-1-3-2-4-3
      192    1-1-1-1-2-2-1-3-1-2
      192    1-1-1-1-2-2-3-1-2-2
      192    1-1-2-1-3-2-4-2-5-3
      192    1-1-1-2-2-3-2-4-1-5
      192    1-1-2-2-1-1-3-2-1-1
      192    1-1-1-2-2-3-1-4-3-5
      192    1-1-2-2-1-1-1-3-3-1
      192    1-1-2-2-3-1-4-1-5-2
      192    1-1-2-1-1-2-1-3-2-2
      192    1-1-2-1-3-2-4-1-5-1
      176    1-1-2-1-1-2-3-3-4-2
      176    1-1-2-2-1-1-2-3-3-2
      176    1-1-2-1-1-2-3-3-4-4
      176    1-1-2-2-3-1-4-2-1-3
      176    1-1-2-1-1-2-3-3-2-4
      176    1-1-2-2-1-3-2-1-3-4
      176    1-1-2-2-1-3-2-1-3-2
      176    1-1-2-2-3-1-1-2-2-3
      160    1-1-2-1-1-2-1-1-3-1
      160    1-1-2-1-1-2-3-1-1-3
      160    1-1-2-2-1-1-1-1-3-1
      160    1-1-2-1-1-2-1-1-3-3
      160    1-1-2-2-1-1-1-1-1-3
      144    1-1-2-2-3-3-1-1-2-2
      144    1-1-2-2-1-3-3-1-4-4
      144    1-1-2-2-3-1-4-3-1-4
      144    1-1-2-2-3-3-1-4-2-1
      144    1-1-2-2-3-3-1-4-4-1
      144    1-1-2-2-1-3-3-4-2-1
      144    1-1-2-2-1-3-3-4-4-1
      144    1-1-2-2-3-3-4-1-1-2
      144    1-1-2-2-3-3-1-1-2-4
      144    1-1-2-2-1-3-3-1-4-2
      144    1-1-2-2-3-3-4-4-1-1
      128    1-1-1-1-2-1-3-1-2-2
      128    1-1-1-2-2-3-2-1-1-4
      128    1-1-2-2-1-3-1-1-3-1
      128    1-1-2-1-1-2-3-1-2-1
      128    1-1-2-2-1-1-1-3-2-4
      128    1-1-2-1-3-2-1-1-4-3
      128    1-1-1-1-2-1-2-1-3-1
      128    1-1-2-2-1-1-2-1-1-3
      128    1-1-1-2-2-3-1-1-3-2
      128    1-1-2-1-1-1-3-2-2-2
      128    1-1-2-1-1-1-1-1-3-1
      128    1-1-2-1-1-1-3-2-2-3
      128    1-1-2-1-1-2-3-2-2-1
      128    1-1-1-2-2-1-1-3-2-2
      128    1-1-2-1-1-2-1-2-3-3
      128    1-1-1-1-1-2-1-2-1-3
      128    1-1-1-2-2-1-3-2-2-1
      128    1-1-2-1-1-2-3-2-2-3
      128    1-1-2-2-1-1-1-1-3-2
      128    1-1-1-2-2-1-1-3-1-4
      128    1-1-1-2-2-1-1-3-3-4
      128    1-1-2-1-1-2-2-2-1-3
      128    1-1-1-2-2-1-3-3-1-2
      128    1-1-1-2-2-1-3-1-2-2
      128    1-1-2-1-3-2-4-1-1-3
      128    1-1-2-1-1-2-1-2-3-1
      128    1-1-1-2-2-1-2-2-1-3
      128    1-1-1-2-2-1-1-3-3-2
      128    1-1-2-1-3-2-1-2-1-3
      128    1-1-2-2-1-1-3-1-4-2
      128    1-1-1-1-2-2-3-3-2-2
      128    1-1-1-2-1-1-1-1-1-3
      128    1-1-1-2-2-1-3-2-2-3
      128    1-1-2-1-3-2-1-2-2-3
      128    1-1-1-2-2-3-3-1-2-1
      128    1-1-1-1-1-2-1-3-1-2
      128    1-1-2-1-1-2-1-2-2-1
      128    1-1-1-2-2-1-2-3-3-2
      128    1-1-1-1-2-2-3-3-1-2
      128    1-1-2-2-3-1-1-1-4-2
      128    1-1-1-2-2-1-2-3-1-4
      128    1-1-2-1-3-2-1-2-2-1
      128    1-1-2-1-3-2-1-2-4-1
      128    1-1-2-1-1-1-3-2-1-2
      128    1-1-2-1-1-2-1-2-1-3
      128    1-1-1-2-2-1-2-1-3-3
      128    1-1-2-2-1-1-1-3-2-2
      128    1-1-2-1-3-2-1-2-4-3
      128    1-1-1-2-2-3-1-1-1-4
      128    1-1-1-2-2-1-3-1-2-3
      128    1-1-2-2-1-1-1-2-3-1
      128    1-1-2-1-3-2-1-3-1-2
      128    1-1-1-2-2-3-3-1-1-4
      128    1-1-1-2-2-1-2-3-3-4
      128    1-1-1-1-2-1-3-1-2-1
      128    1-1-1-2-1-1-1-3-2-2
      128    1-1-1-2-2-3-1-1-3-4
      128    1-1-2-1-1-2-1-2-2-3
      128    1-1-2-2-1-1-1-2-3-3
      128    1-1-2-1-3-2-1-1-4-1
      128    1-1-1-2-2-1-2-1-3-1
       96    1-1-1-2-2-3-3-4-2-5
       96    1-1-2-2-1-3-1-4-1-5
       96    1-1-2-2-3-3-1-4-1-5
       96    1-1-2-2-3-1-4-1-5-3
       96    1-1-2-2-1-3-3-4-1-5
       96    1-1-2-1-3-2-4-3-5-2
       96    1-1-2-2-3-3-4-1-5-1
       96    1-1-2-2-1-1-1-1-3-3
       96    1-1-2-2-1-3-1-4-3-5
       96    1-1-2-2-1-3-2-4-1-5
       96    1-1-2-2-3-1-4-2-5-3
       96    1-1-2-2-1-3-2-4-3-5
       96    1-1-2-2-3-1-1-1-1-3
       96    1-1-2-1-3-2-4-3-5-4
       96    1-1-1-2-2-3-3-4-4-5
       96    1-1-2-2-3-1-4-2-5-1
       96    1-1-2-2-3-1-4-3-5-1
       96    1-1-2-2-3-1-4-1-5-1
       64    1-1-2-2-1-3-1-1-3-4
       64    1-1-2-2-3-1-1-3-4-1
       64    1-1-2-2-3-1-1-1-2-3
       64    1-1-1-2-2-3-3-1-2-4
       64    1-1-2-2-3-1-1-1-4-1
       64    1-1-2-2-1-1-3-2-4-3
       64    1-1-2-1-1-2-2-3-1-2
       64    1-1-2-2-1-3-3-1-1-4
       64    1-1-1-2-2-1-2-1-1-3
       64    1-1-2-2-1-1-3-2-2-3
       64    1-1-2-1-1-2-3-3-2-2
       64    1-1-1-2-2-3-3-1-2-2
       64    1-1-2-1-3-2-1-3-2-2
       64    1-1-2-2-1-1-3-3-4-1
       64    1-1-2-2-3-1-1-1-4-3
       64    1-1-2-2-3-1-1-3-1-4
       64    1-1-2-2-1-1-3-2-1-3
       64    1-1-2-2-1-1-3-3-2-1
       64    1-1-1-2-1-1-2-3-1-2
       64    1-1-2-2-1-1-3-3-1-4
       64    1-1-2-2-1-1-3-2-2-1
       64    1-1-2-2-3-3-1-1-4-1
       64    1-1-2-2-1-1-3-1-4-1
       64    1-1-2-1-1-2-3-1-2-2
       64    1-1-1-1-2-1-2-2-1-2
       64    1-1-2-2-3-3-1-1-1-4
       64    1-1-2-2-1-1-2-3-1-2
       64    1-1-1-1-2-2-3-1-2-3
       64    1-1-2-1-1-2-1-3-1-2
       64    1-1-2-2-1-3-3-1-2-1
       64    1-1-2-2-1-3-1-1-3-2
       64    1-1-2-2-1-3-1-1-1-4
       64    1-1-2-1-1-2-3-1-2-3
       64    1-1-2-2-1-1-3-2-4-1
       64    1-1-2-2-1-1-1-3-1-4
       64    1-1-2-1-3-2-4-3-1-2
       64    1-1-2-2-3-1-1-3-2-1
       64    1-1-2-2-1-3-2-1-1-4
       64    1-1-2-2-1-1-3-1-4-3
       64    1-1-2-1-1-2-3-3-1-2
       64    1-1-2-2-3-1-4-1-1-3
       64    1-1-1-2-2-1-3-3-2-2
       64    1-1-1-1-2-2-2-3-1-2
       64    1-1-2-2-1-1-1-3-3-4
       48    1-1-2-2-1-3-3-4-2-5
       48    1-1-2-2-3-1-4-3-5-4
       48    1-1-2-2-1-3-3-4-4-5
       48    1-1-2-2-3-3-4-4-5-1
       48    1-1-2-2-3-3-1-4-4-5
       48    1-1-2-2-3-3-1-4-2-5
       48    1-1-2-2-3-3-4-4-1-5
       48    1-1-2-2-3-3-4-1-5-4
       48    1-1-2-2-3-1-4-3-5-2
       48    1-1-2-2-3-3-4-1-5-2
       32    1-1-2-2-1-1-3-3-4-4
       32    1-1-2-2-3-1-1-3-4-2
       32    1-1-2-2-1-3-3-1-2-2
       32    1-1-2-2-1-3-3-1-2-4
       32    1-1-2-2-3-3-1-1-4-4
       32    1-1-2-2-1-1-3-3-2-2
       32    1-1-2-2-3-3-1-1-4-2
       32    1-1-2-2-1-1-3-1-1-3
       32    1-1-2-2-3-1-1-3-2-4
       32    1-1-2-2-1-1-3-3-4-2
       32    1-1-2-2-3-1-4-3-1-2
       32    1-1-2-2-1-1-3-3-2-4
       32    1-1-2-2-3-1-1-3-2-2
       32    1-1-2-2-3-3-4-1-1-4
       32    1-1-2-2-3-1-1-3-4-4
       16    1-1-2-2-3-3-4-4-5-5
  1048576    Total Routes
   441200    Returned to origin which is 42%


Frequency    Coordinate
   653904    (0,-1)
   653904    (0,1)
   653904    (0,0)
   653904    (-1,0)
   653904    (1,0)
   421816    (-1,1)
   421816    (1,-1)
   421816    (1,1)
   421816    (-1,-1)
   282948    (2,0)
   282948    (0,-2)
   282948    (-2,0)
   282948    (0,2)
   189728    (1,-2)
   189728    (1,2)
   189728    (-1,-2)
   189728    (2,1)
   189728    (-2,-1)
   189728    (-1,2)
   189728    (-2,1)
   189728    (2,-1)
   116896    (2,-2)
   116896    (-2,2)
   116896    (-2,-2)
   116896    (2,2)
    98432    (0,-3)
    98432    (-3,0)
    98432    (0,3)
    98432    (3,0)
    89712    (-3,1)
    89712    (3,1)
    89712    (1,3)
    89712    (-3,-1)
    89712    (1,-3)
    89712    (-1,3)
    89712    (3,-1)
    89712    (-1,-3)
    44064    (3,-2)
    44064    (-3,2)
    44064    (-2,-3)
    44064    (-2,3)
    44064    (2,3)
    44064    (-3,-2)
    44064    (3,2)
    44064    (2,-3)
    40256    (0,4)
    40256    (4,0)
    40256    (0,-4)
    40256    (-4,0)
    26624    (-1,-4)
    26624    (-4,1)
    26624    (-1,4)
    26624    (4,-1)
    26624    (1,4)
    26624    (-4,-1)
    26624    (4,1)
    26624    (1,-4)
    25420    (3,3)
    25420    (3,-3)
    25420    (-3,3)
    25420    (-3,-3)
    20458    (-4,2)
    20458    (-2,4)
    20458    (-2,-4)
    20458    (-4,-2)
    20458    (2,-4)
    20458    (4,-2)
    20458    (4,2)
    20458    (2,4)
    10520    (-1,5)
    10520    (5,1)
    10520    (-1,-5)
    10520    (-5,-1)
    10520    (1,5)
    10520    (5,-1)
    10520    (1,-5)
    10520    (-5,1)
     9344    (0,5)
     9344    (-5,0)
     9344    (5,0)
     9344    (0,-5)
     6776    (-3,-4)
     6776    (3,-4)
     6776    (-4,3)
     6776    (4,-3)
     6776    (-4,-3)
     6776    (-3,4)
     6776    (3,4)
     6776    (4,3)
     4368    (-2,5)
     4368    (2,-5)
     4368    (5,2)
     4368    (-5,2)
     4368    (-5,-2)
     4368    (5,-2)
     4368    (2,5)
     4368    (-2,-5)
     3640    (4,-4)
     3640    (-4,-4)
     3640    (4,4)
     3640    (-4,4)
     3305    (0,-6)
     3305    (-6,0)
     3305    (0,6)
     3305    (6,0)
     2996    (-5,3)
     2996    (5,-3)
     2996    (-3,5)
     2996    (-3,-5)
     2996    (5,3)
     2996    (3,5)
     2996    (-5,-3)
     2996    (3,-5)
     1744    (6,-1)
     1744    (1,-6)
     1744    (6,1)
     1744    (1,6)
     1744    (-1,6)
     1744    (-6,1)
     1744    (-6,-1)
     1744    (-1,-6)
     1648    (-6,2)
     1648    (6,2)
     1648    (-2,-6)
     1648    (-6,-2)
     1648    (-2,6)
     1648    (2,-6)
     1648    (6,-2)
     1648    (2,6)
      578    (1,7)
      578    (-7,-1)
      578    (7,-1)
      578    (7,1)
      578    (-1,7)
      578    (-1,-7)
      578    (-7,1)
      578    (1,-7)
      504    (5,-4)
      504    (4,-5)
      504    (-4,-5)
      504    (-5,4)
      504    (-5,-4)
      504    (-4,5)
      504    (4,5)
      504    (5,4)
      388    (-7,0)
      388    (0,7)
      388    (7,0)
      388    (0,-7)
      336    (3,-6)
      336    (-6,-3)
      336    (-3,6)
      336    (-3,-6)
      336    (-6,3)
      336    (6,3)
      336    (6,-3)
      336    (3,6)
      252    (-5,-5)
      252    (-5,5)
      252    (5,5)
      252    (5,-5)
      210    (6,4)
      210    (-4,-6)
      210    (-6,4)
      210    (4,6)
      210    (-4,6)
      210    (6,-4)
      210    (-6,-4)
      210    (4,-6)
      144    (-7,2)
      144    (2,-7)
      144    (-2,-7)
      144    (2,7)
      144    (-2,7)
      144    (-7,-2)
      144    (7,2)
      144    (7,-2)
      120    (7,-3)
      120    (7,3)
      120    (3,7)
      120    (3,-7)
      120    (-7,3)
      120    (-7,-3)
      120    (-3,-7)
      120    (-3,7)
      116    (-8,0)
      116    (0,-8)
      116    (0,8)
      116    (8,0)
       45    (2,8)
       45    (8,2)
       45    (-8,2)
       45    (-8,-2)
       45    (8,-2)
       45    (-2,-8)
       45    (-2,8)
       45    (2,-8)
       36    (1,-8)
       36    (8,1)
       36    (-1,-8)
       36    (8,-1)
       36    (-8,1)
       36    (-8,-1)
       36    (-1,8)
       36    (1,8)
       10    (-1,-9)
       10    (-1,9)
       10    (9,1)
       10    (9,-1)
       10    (-9,1)
       10    (1,-9)
       10    (1,9)
       10    (-9,-1)
        4    (0,-9)
        4    (-9,0)
        4    (0,9)
        4    (9,0)
        1    (10,0)
        1    (0,-10)
        1    (-10,0)
        1    (0,10)


Direction    Frequency
        1      2621440
        2      2621440
        3      2621440
        4      2621440


 Distance    Frequency    Cumulative
        0       653904    
        1      3269520    10%
        2      6088576    50%
        3      8467712    
        4      9698944    90%
        5     10268864    
        6     10439716    
        7     10475124    
        8     10485012    
        9     10485676    
       10     10485760    100%


For Random Walk of 2 dimensions and 10 steps,
distance at which N percent of coordinates are contained
        1           10%
        2           50%
        4           90%
       10          100%


Timing Data: 36.195 seconds to run
Random Walk example using SVG Animation
Random Walk SVG or PNG



Here's the code to handle a 2D Random Walk
sub do_walk_2D {
   my ($steps) = @_;                  # Pass in number of steps to take
   my (@coords_array, $direction, $step, $x, $y);
   $x = $y = $coords_array[1][0] = $coords_array[2][0] = 0;
   print "Step   Direction       X    Y\n";
   for ( $step = 1 ; $step <= $steps ; $step++ ) {
      $direction = int(4*rand()) + 1;
      if ( $direction == 1 ) {        # West
         $x--;
      } elsif ( $direction == 2 ) {   # East
         $x++;
      } elsif ( $direction == 3 ) {   # South
         $y--;
      } elsif ( $direction == 4 ) {   # North
         $y++;
      }
      $coords_array[1][$step] = $x;
      $coords_array[2][$step] = $y;
      $string = sprintf "%4s%12s%9s%5s", $step, $direction, $x, $y;
      print "$string\n";
   }
   return @coords_array;    # 2D array of coordinate points 1-x and 2-y
}


But lets rewrite it generically for any Dimension!
sub do_walk {
   my ($dimensions, $steps, $option, @force_dirs) = @_;
   my (@coords_array, $dimension, $direction, $directions, $neg_pos, $step);
   $directions = 2*$dimensions; # 1D has two directions, 2D-four, 3D-six, etc.
   for ($dimension = 1 ; $dimension <= $dimensions ; $dimension++ ) {
      $coords_array[$dimension][0] = 0;
   }
   for ( $step = 1 ; $step <= $steps ; $step++ ) {
      for ($dimension = 1 ; $dimension <= $dimensions ; $dimension++ ) {
         $coords_array[$dimension][$step] = $coords_array[$dimension][$step - 1];
      }
      if ( $option eq 1 ) {                         
         $direction = int($directions*rand()) + 1; # Normal random behavior
      } else {
         $direction = $force_dirs[$step];  # Use specified direction for iteration
      }
      $neg_pos = -2*($direction%2) + 1;    # Decrement if odd, Increment if even
      # Update the coordinate that changes in the right direction
      $coords_array[int(($direction+1)/2)][$step] += $neg_pos;
   }
   return @coords_array;    # 2D array of coordinate points 1-x, 2-y, 3-z, etc.
}


Note the ability to specify the direction in the code above - this is used when iterating over all possible routes
for ($step = 1 ; $step <= $steps ; $step++ ) {
      $directions_force[$step] = 1;
   }
   for ($iteration = 1 ; $iteration <= $directions**$steps ; $iteration++ ) {
      &do_walk($dimensions, $steps, $options{'iterations'}, @directions_force);
      $directions_force[$steps]++;
      for ($step = $steps ; $step >= 1 ; $step-- ) { # 111, 112, 113, 114, 121, etc.
         if ($directions_force[$step] > $directions) {
            $directions_force[$step] = 1;
            $directions_force[$step-1]++;
         }
      }
   }


The rest of the program is basically just data wrangling the @coords_array - here are the options
random-walk [-dimensions=#] [-steps###]   (defaults are 2 and 5)
   [-benchmark]         Generate and display benchmark timing info
   [-debug]             Turn on debugging output
   [-iterate]           Do ALL possible routes rather than just a single Random Walk
                           This takes much longer to run - can generate LOTS of output
   [-srand_seed=#]      Set random seed to # for repeatable rather than random results
   [-usage]             Show this page

   [-show_all]          Show all of the below
   [-show_coords]       For each step, show direction taken and coordinates
   [-show_coords_freq]  Show frequency distribution of coordinates
   [-show_directions]   Show frequency distribution of directions
   [-show_distances]    Show frequency distribution of distance from origin
   [-show_iter_dir]     Show iteration directions
   [-show_stepped_on]   Show "stepped on" coordinates as walk progresses
   [-show_stepped_ons]  Show frequency distribution of "stepped on" coordinates

Please contact me with any suggestions/corrections