Last active
December 19, 2015 15:38
-
-
Save sahands/5977365 to your computer and use it in GitHub Desktop.
Fair Coin from Unfair Coin - Groupon Interview Question
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def bernoulli_process(p): | |
if p > 1.0 or p < 0.0: | |
raise ValueError("p should be between 0.0 and 1.0.") | |
while True: | |
yield random.random() < p | |
def von_neumann_extractor(process): | |
while True: | |
x, y = process.next(), process.next() | |
if x != y: | |
yield x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment