Previous laboratory work simulated the rolling of a die, by defining a procedure roll-a-die using Chez Scheme's random procedure to obtain random integers 1, 2, 3, 4, 5, and 6. That work also simulated the rollng of a die several times, showing the results of each of n tosses. The resulting procedure was called roll.
We can simulate the rolling a pair of dice by calling roll-a-die twice -- perhaps making a list out of the two results:
(define pair-of-dice
(lambda ()
(list (roll-a-die) (roll-a-die))
)
)
(define seven-or-11
(lambda (n)
(cond ((<= n 0) 0)
((or (= (sum-of-dice) 7) (= (sum-of-dice) 11))
(+ 1 (seven-or-11 (- n 1))))
(else (seven-or-11 (- n 1)))
)
)
)
Challenge Problem 2:
Write a procedure double-heads which tosses a coin n
times and determines whether a head ever comes up twice in a row.
(Hint: You might try adding another parameter which indicates if the
previous toss were a head.)
Challenge Problem 3: Modify the previous procedure to record the number of times a double head is obtained when a coin is tossed n times. (In your counting, you should consider three heads in a row as two double heads.)
Challenge Problem 4: Modify your procedure from Challenge Problem 2, so that it continues the simulation until a double head appears and then prints the number of flips that were required to get the double head.
Work to be turned in:
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/151.fa00/lab-simulation.html