Professional Documents
Culture Documents
Stat230 Spring2023 Comp
Stat230 Spring2023 Comp
Solve by simulation the following problems. Please return all your codes in
one single text file and specify clearly the question each algorithm is meant to
answer. Write comments in the important parts of the code.
1. A coffee set has six cups and six saucers. Three cups and three saucers
are white, and the other three are blue. The cups are placed at random
on the saucers. Let N be the number of cups that match the colors of the
saucers they are on. Obtain an estimate of the pmf of N .
2. Roll three regular and fair dice one after the other. Then do the same a
second time.
a) What is the probability that the three numbers recorded in the first
three rolls match those in the second three rolls as well as the order
in which they appear?
b) What is the probability that the three numbers recorded in the first
three rolls match those in the second three rolls irrespective of the
order in which they appear?
3. An algorithm to make a fair coin unfair.
Consider the binary representation of a number q in [0, 1].
It has the form 0.x1 x2 . . . where xi = 0 or xi = 1. The sequence of zeros
and ones after the point, i.e. x1 x2 x3 . . ., is called the binary expansion of
q. The decimal expression of q can be read from the binary expansion.
Namely,
∞
X xi
q= ,
i=1
2i
that is, when the binary digit after the point is 1 we add 1/2 to the power
of its position in the binary expansion.
Some examples.
The number 0.5 = 1/2 is in binary form 0.1, or by making the trailing 0’s
explicit, which is what we would need, we would write it as
1/2 7→ 0.100000000000000000000000 . . .
1/3 7→ 0.01010101010101010101010 . . . .
With this understood, let us construct a biased coin with p(H) = P (1) =
p ̸= 1/2 using a fair coin. This is the algorithm.