Created
January 25, 2018 04:42
-
-
Save iconjack/0e41903e44e3ece4f4d47b2200e99c70 to your computer and use it in GitHub Desktop.
This file contains 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 | |
N = 2018 | |
trials = 10000 | |
def connect(wires): | |
loops = 0 | |
while wires > 1: | |
v, w = random.randrange(wires), random.randrange(wires) | |
if v == w: | |
if random.random() < .5: | |
loops += 1 | |
else: | |
continue | |
wires -= 1 | |
return loops+1 | |
print(sum(connect(N) for _ in range(trials))/trials) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment