O'Reilly logo

Digital Dice by Paul J. Nahin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Solutionimage

image

18. Waiting for Stoplights

The code walk.m simulates our pedestrian’s walk from (m + 1, m + 1) to (1,1) a hundred thousand times, for any given value of m. Lines 01 and 02 respectively bring in the value of m to be used and initialize the variable totalwait to zero. When the program terminates, totalwait will be the total number of red lights encountered in 100,000 simulated walks from (m + 1, m + 1) to (1,1). Lines 03 and 26 define the for/end loop that simulates a single one of those walks. At the start of a walk, lines 04 and 05 set ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required