# how much exp if I catch 2 pidgeys and 4 ratatas?
# here 2 pidgey is expressed as (2, 12) where 2 is number of pidgey
# and 12 is how many candy it takes for a pidgey to evolve
# the same goes to ratata, 4 ratatas, and a ratata takes 25 candies
caught = [(2, 12), (4, 25)]
# You can compute how much exp is a single pokemon (such as a ratata) by catching only 1 of it
# uncomment this code to find out
# caught = [(1, 25)]
# are you using egg? True or False
lucky_egg = True
###### CODE #######
# the short-hand formula to find out how much experience
# is a pokemon given its cost to evolve
def exp_worth_poke(candies_to_evolve):
return 100 + 500.0 / ((candies_to_evolve - 1) / 4.0) * 2.0
# given you caught a new pokemon, can you evolve it?
# returns a tuple (can_evolve, candy_after_evolve)
def evolve1(n_candy, num_to_evolve):
# a new pokemon is added, we get 3 more candies
cur_candy = n_candy + 3
# if cannot evolve, sell it and store 1 more candy
if cur_candy < num_to_evolve:
return (0, cur_candy + 1)
# otherwise, evolve the pokemon, consuming the candies
else:
candy_after_evo = cur_candy - num_to_evolve
# evolution grants 1 candy, selling the poke 1 extra
return (1, candy_after_evo + 2)
# if you have n_candy at start
# given the cost of candy it takes to evolve
# and the number of pokemon you caught
# what's the final number of evolution u can afford and candy leftover
def evolve_n(n_candy, num_to_evolve, num_poke_caught):
cur_state = (0, n_candy)
for i in range(num_poke_caught):
# print cur_state
num_evol, n_candy = cur_state
additional_evol, res_candy = evolve1(n_candy, num_to_evolve)
cur_state = (num_evol + additional_evol, res_candy)
return cur_state
# find the average evolution
def avg_evol(num_to_evolve):
# mapping from num_candy to num_of evolves and num_poke at that point
seen_states = dict()
# the cur_state is (num_evol, num_candy)
cur_state = (0, 0)
pokemon_caught = 0
while True:
# print cur_state
num_evol, num_candy = cur_state
if num_candy in seen_states:
previous_evol, previous_caught = seen_states[num_candy]
current_evol = num_evol
return float(num_evol - previous_evol) / (pokemon_caught - previous_caught)
else:
seen_states[num_candy] = (num_evol, pokemon_caught)
pokemon_caught += 1
additional_evol, res_candy = evolve1(num_candy, num_to_evolve)
cur_state = (num_evol + additional_evol, res_candy)
def exp_worth_evo(num_to_evolve):
return 500.0 * avg_evol(num_to_evolve)
def total_evo_exp(lst_caught):
ret = 0.0
for xx in lst_caught:
num, lvl_candy = xx
ret += exp_worth_evo(lvl_candy) * num
return ret
def total_exp(lst_caught, lucky_egg):
multi = 1
if lucky_egg:
multi = 2
num_poke = sum([x[0] for x in lst_caught])
return total_evo_exp(lst_caught) * multi + 100 * num_poke
print "you have made this many exp: "
print total_exp(caught, lucky_egg)