Skip to content

Instantly share code, notes, and snippets.

@iconjack
Created January 25, 2018 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iconjack/0e41903e44e3ece4f4d47b2200e99c70 to your computer and use it in GitHub Desktop.
Save iconjack/0e41903e44e3ece4f4d47b2200e99c70 to your computer and use it in GitHub Desktop.
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