Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

STAT 230 SPRING 2023-T1-COMPUTATIONAL PART

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 . . .

so that the binary expansion 100 . . . with an infinite number of digits.


Similarly,

X
2/3 = 1/22k+1 7→ 0.1010101010101010101010101 . . .
k=0

The binary representation of p = 1 − q is obtained from that of q by


switching 0 and 1 in the binary expansion. Thus

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.

Take a fair coin. Write the binary expansion of q = P (0) = P (T ) = 1 − p,


the chosen probability of getting a 0 in the biased coin. Start tossing
the fair coin and write down the outcome (1 or 0). As you are tossing,
compare the outcomes of the tosses with the binary expansion of q. Stop
tossing when the two sequences do not match, and output the outcome of
the last toss. Such algorithm that outputs at each instance the outcome
(1 or 0) of the toss when the mismatch occurs is tantamount to tossing an
unfair coin with P (1) = p. Convince yourself that this is indeed the case
(you can prove it, if you wish, the same way you have proven, or should
have proven, the result in the first part of the exam). Think about how
nice this result is. The exercise in the first part of the exam was about
this algorithm for p = 1/3 (or p = 6/7).
Implement the algorithm and apply it for three or four values of p and
verify by simulation that it does indeed work. Compute also the expected
number of coin tosses it takes to output a 0 or 1. Does it depend on p?

Since the binary expansion is infinite, in your implementation you will


have to input a truncation of the binary expansion of q.
4. Jihad lives in an apartment building. He is aware that two new tenants
who are students have just moved in the only other apartment on his floor.
One morning on his way out he finds a book about spin glasses in front
of the elevator door. He picks it up and rings the bell of his neighbors’
apartment to return it. A neighbor opens the door and they introduce
each other: she is a physics student. Before he talks about and hands out
the book he found, Jihad computes the probability that she is the owner
of the book. What is it?
To compute it, assume, as Jihad did, that only physics students read that
book; that the book belongs to one of the neighbors; that each neighbor
is as likely to be a physics student as not.
You may also assume that only one student would open the door (before
the evidence that this is so). Although this is not necessary, the sample
space and the coding will differ whether this assumption is made or not.

You might also like