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

image

image

7. The Pipe Smoker’s Discovery

The code smoker.m simulates the problem one million times, as controlled by the for/end loop defined by lines 03 and 16. Before beginning those simulations, however, line 01 initializes the variable S to zero, where the value of S will, at the completion of each simulation, be the current total number of matches used (and so, when the program completes the last of the one million simulations, S/1000000, as computed in line 17, will be the answer to the original question, i.e., the average number of matches removed ...

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