The “Prime Sided Dice” logic puzzle was all about simulating fair dice using other fair dice. In this puzzle, we limit ourselves even further and try to simulate a fair die using only coins.

Imagine you have k coins, which are not necessarily fair. You get to choose the bias for each of the coins. (i.e. You choose the probability that each coin comes up heads.) You may then use whatever procedure you like to simulate a fair n-sided die. You are allowed to flip the same coin more than once. The catch is that your procedure must end in some bounded number of coin flips.

For example, if you have a coin that comes up heads with probability 1/3, and another coin that comes up heads with probability 1/2, then you can simulate a 3-sided die by flipping the first coin, returning 1 if you get heads, and otherwise flipping the second coin and returning 2 or 3 depending on the result.

As a function of n, what is the minimum number k of coins that you need? (i.e. Which dice can be simulated with 1 coin? 2 coins? 3 coins? etc.)

The solution will eventually be posted in the comments. If you have been working on this puzzle for a while, and are starting to lose interest, please make sure you view this minor hint before you give up. I advise anyone who has been working on this puzzle for more than an hour to just view the hint. It is more interesting than it is helpful. (Written in rot13, decode here.)

Read 9 comments

For a given N we can use N-1 coins biased 1/N, 1/(N-1), …, 1/2. Rolling them in that order, we let the first occurrence of heads be our roll. For example

H = 1
TH = 2
TTH = 3
…

It is easy to see that the probability of rolling a k is 1/N. Let’s call this algorithm the “N-coin-flip”.

Let the prime factorization of N be

p_1^a_1 p_2^a^2 … p_k^a_k

where p_1 < p_2 < … < p_k. Then we only need p_k -1 coins with at most sum{(p_i – 1) a_i} coin flips. The algorithm goes as follows. Split N into p_1 intervals of length N/p_1. Then do a "p_1-coin-flip" to determine which interval to proceed and then repeat. For example, let N = 63 = 3^2 7

If n is odd flip a coin with P(heads)=(n-1)/2 and a coin with P(heads)=n/(n-1). You can use the results to partition n=2m+1 as (m,m,1) by using (H,TH,TT). Then the problem has been reduced to the problem for m=(n-1)/2.

Each step takes at most two flips and there are log2(n) steps. So we’re done in 2log2(n).