CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [minorsecond] Creating a 100x100 grid in perl: Edit Log

Chris Charley

Sep 24, 2012, 1:45 PM

Views: 4753
Re: [minorsecond] Creating a 100x100 grid in perl

The variable @grid could have more accurately named @path. If I understand the problem correctly, you want a (100 x 100) grid that remains constant from run to run and have random walks through that grid. (The @path var is @grid in the original code).

push @walks, scalar grep $_, @path[0 .. $steps - 1];

The line above takes $steps steps. The grid in effect remains constant, its only the path that changes for each run.

I did a similar problem in school in C++ and I can't find it now. It used a grid of letters and I had to find a (given) list of words in it. We could move in any direction, even diagonally, to find the words.

Have you tried it and does it give reasonable results? I would have to think about this more and then post back if I discover the error or correctness in the program.

I think it is how you look at it. The path is changing from run to run - it is random. The number of contaminated cells does not change from run to run.

Hope that helps and that I've understood the problem.

Just doing the math, if there are 100 contaminated cells out of 10,000 (in a 100 X 100 grid), then 1% of them are contaminated. The probability of taking 100 steps without stepping on a contaminated cell would be .99 to the hundreth power, (.99 ^ 100). That gives ~0.36 and I get results close to that when running my program (when using those parameters).

Update: My model solution doesn't account for the possibilty of revisiting a cell. I think the answer lies in creating a grid to randomly walk upon - as your problem originally suggested.

(This post was edited by Chris Charley on Sep 28, 2012, 1:46 PM)

Edit Log:
Post edited by Chris Charley (User) on Sep 28, 2012, 1:39 PM
Post edited by Chris Charley (User) on Sep 28, 2012, 1:42 PM
Post edited by Chris Charley (User) on Sep 28, 2012, 1:46 PM

Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives