Skip to content

Instantly share code, notes, and snippets.

@galenseilis
Created October 17, 2022 01:27
Show Gist options
  • Select an option

  • Save galenseilis/e5c1d080a98386b26a4996abd7738d8f to your computer and use it in GitHub Desktop.

Select an option

Save galenseilis/e5c1d080a98386b26a4996abd7738d8f to your computer and use it in GitHub Desktop.
from itertools import chain, combinations
from random import sample
import matplotlib.pyplot as plt
def powerset(iterable):
s = list(iterable)
return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))
pX = [set(i) for i in powerset(list(range(10)))]
results = []
N = 1000
for k in range(10000):
count = 0
for i in range(N):
A,B = sample(pX, 2)
if A.issubset(B):
count += 1
else:
continue
results.append(count / N)
plt.hist(results, bins=100)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment