The von Neumann trick clicked for me pretty fast: call the biased function twice, if you get (0,1) output 0, if (1,0) output 1, otherwise discard and retry.
Use the von Neumann extractor to generate fair bits from pairs of biased coin flips, then combine bits to produce a uniform integer from 0 to 6. Analyze the expected number of calls and optimize by using rejection sampling with a larger bit budget to reduce waste.
Pro tip: Mention that the expected number of calls can be reduced by generating multiple fair bits per pair and using rejection sampling with a buffer, but note the trade-off between complexity and efficiency.
Explain how to use the biased coin to generate fair bits by flipping twice: if outcomes are (0,1) output 0, if (1,0) output 1, otherwise discard and repeat.
Use the fair bits to generate a uniform integer in a range. Since 7 is not a power of 2, use rejection sampling: generate 3 fair bits to get a number 0-7, reject 7, and return the result.
Calculate the expected number of biased coin flips: each fair bit requires 1/(2p(1-p)) pairs on average, and each integer requires 8/7 fair bits on average, so total expected flips = (8/7) * (1/(p(1-p))).
Discuss how to minimize calls by generating multiple fair bits at once and using a buffer to reduce rejection waste, or by using a more efficient extraction method like Elias's algorithm.
Consider cases where p=0 or p=1 (coin always returns same value), and discuss fallback or error handling.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.