Skip to content

Instantly share code, notes, and snippets.

@EvanTheB
Created August 10, 2018 06:26
Show Gist options
  • Save EvanTheB/a754b3cc29a0fdd3a13b92c046ce1a63 to your computer and use it in GitHub Desktop.
Save EvanTheB/a754b3cc29a0fdd3a13b92c046ce1a63 to your computer and use it in GitHub Desktop.
import random
import collections
def num_cards():
cures = [0] * 48 + [1] * 4
random.shuffle(cures)
def split(x, n):
return [x[i:len(x):n] for i in range(n)]
cures = [c + [2] for c in split(cures, 5)]
[random.shuffle(c) for c in cures]
cures = [item for sublist in cures for item in sublist]
# print (cures)
top = [0]
dis = [9]
rate = [4,4,3,3,2,2,2]
while len(cures) > 1:
def take():
c = cures.pop()
if (c == 2):
rate.pop()
top[0] = max(0, top[0])
top[0] += dis[0] + 1
dis[0] = 0
def inf():
dis[0] += 1
top[0] -= 1
take()
take()
[inf() for i in range(rate[-1])]
#print(top, dis, rate[-1])
return max(top[0], 0) + dis[0]
def per_region(l, num_cards, target_set):
def do_it():
d = list(range(4)) * 12
d = random.sample(d, num_cards)
d = collections.Counter(d)
if any(d[i] in target_set for i in range(4)):
return True
return False
return sum(1 for x in range(l) if do_it() == True) / l
print ("num_cards", sum(num_cards() for _ in range(1000))/1000)
print ("per_region 0", per_region(10000, 12, [0]))
print ("per_region 1", per_region(10000, 12, [1]))
print ("per_region 01", per_region(10000, 12, [0,1]))
print ("per_region 012", per_region(10000, 12, [0,1,2]))
from matplotlib import pyplot as plt
plt.hist([num_cards() for i in range(1000)])
plt.show()
plt.plot(list(range(10,25)), [per_region(1000, i, [0,1]) for i in range(10,25)])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment