Created
April 15, 2011 04:45
-
-
Save mathewbyrne/921155 to your computer and use it in GitHub Desktop.
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
import sys | |
import random | |
all_stats = ['HP', 'Attack', 'Defense', 'Special Attack', 'Special Defense', 'Speed'] | |
def catch_ditto(): | |
'''Catches a Ditto with a 1/6 chance of having a random max IV value''' | |
max_ivs = [] | |
for stat in all_stats: | |
value = random.randint(0, 31) | |
if value == 31: | |
max_ivs.append(stat) | |
return max_ivs | |
def get_all_ivs(): | |
'''Returns the number of pokemon caught before all stats have max IV''' | |
max_ivs_caught = [] | |
attempts = 0 | |
while len(max_ivs_caught) < len(all_stats): | |
attempts += 1 | |
max_ivs = catch_ditto() | |
for max_iv in max_ivs: | |
if max_iv is not None and max_iv not in max_ivs_caught: | |
max_ivs_caught.append(max_iv) | |
return attempts | |
if __name__ == '__main__': | |
count = int(sys.argv[1]) | |
sum_catches = 0 | |
catches = 0 | |
for i in range(count): | |
catches += 1 | |
sum_catches += get_all_ivs() | |
print 'On average %d catches' % (sum_catches // catches) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment