Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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