Created
September 30, 2013 12:23
-
-
Save jepler/6763003 to your computer and use it in GitHub Desktop.
Python program that simulates habitrpg drops; each output line is "number of drops until full stable", "greatest number of excess eggs of any type", "greatest number of excess potions of any type".
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
#!/usr/bin/python | |
from __future__ import division | |
import bisect | |
import random | |
import sys | |
# 9 animal types - even probability | |
# 10 potion types - uneven probability | |
# 1/5: set of 10 | |
# 1/5: set of 9 | |
# 1/5: set of 6 | |
# 2/5: set of 3 | |
def main(): | |
pa = [1/9.] * 9 | |
pb = [0] * 10 | |
for i in range(3): pb[i] += (2/5. * 1/3.) | |
for i in range(6): pb[i] += (1/5. * 1/6.) | |
for i in range(9): pb[i] += (1/5. * 1/9.) | |
for i in range(10): pb[i] += (1/5. * 1/10.) | |
cpa = [sum(pa[:i+1]) for i in range(len(pa))] | |
cpb = [sum(pb[:i+1]) for i in range(len(pb))] | |
#for i, j in zip(pb, cpb): print "%.1f%% %.1f%%" % (100*i, (100*j)) | |
def do_drop(cp, c): | |
r = random.random() | |
i = bisect.bisect_right(cp, r) | |
c[i] += 1 | |
ca = [0] * 9 | |
cb = [0] * 10 | |
while min(ca) < len(ca) or min(cb) < len(cb): | |
r = random.random() | |
if r < .5: | |
do_drop(cpa, ca) | |
else: | |
do_drop(cpb, cb) | |
print sum(ca+cb), max(ca) - len(ca), max(cb) - len(cb) | |
for i in range(1000): | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment