We are given a (2k+1) by (2k+1) grid, say (G[i,j]: i=-k...k, j=-k...k). You are to write a program to determine by simulation, the probability that the boundary can be reached from the starting point (0,0). This is done by doing t trials, counting the number that succeed in reaching the boundary, and then dividing this by t to find the probabilty of escape. A boundary point is any point G[i,j] such that either i or j is k or -k.
On any one trial, the probability that there is a gap between a grid point (i,j) and its neighbour (i+1,j) is determined by p and this probability stays constant for one trial. This is also true for the other three neighbours of point (i,j). The value for p is to be input but the probability of a gap will be generated by a random number generator.
Note: Efficiency is of some concern here and re-initializing the grid for each trial may be too costly. Programs will only be allowed to run for 2 minutes.
where k, p, and t are as defined above, and esc is the proportion of trials that led to an escape, that is the probability of escape. You should give the value of esc to two decimal places.
1 10 0.45 100
10 0.45 100 0.47
Note: If you run your program several times with the data given above, you would not expect to get exactly the same value of esc for each run.