Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- def lps(planted):
- """Lollipops per second."""
- return math.ceil(100*(1-math.exp(-(planted-20)/5000)))
- ###########
- # The question is, what is the optimal number of lollipops to plant so that we can reach 5000 lollipops on-hand?
- # I think this is a Golden Mean Bisection problem.
- def plantuntil(intialPlanted, untilPlanted, mult=3, pops=0):
- seconds = 0
- lollipops = pops
- planted = intialPlanted
- while planted < untilPlanted:
- seconds += 1
- lollipops += lps(planted)*mult
- nowPlant = min(lollipops, untilPlanted - planted)
- lollipops -= nowPlant
- planted += nowPlant
- while lollipops < 5000:
- seconds += 1
- lollipops += lps(planted)*mult
- return seconds
- initialPlanted = 1554
- initialOwned = 2673
- mult = 3*3
- best = 1000
- besti = 0
- for i in range(initialPlanted,5000):
- candidate = plantuntil(initialPlanted, i, mult=mult, pops=initialOwned)
- if candidate <= best:
- best = candidate
- besti = i
- #print(i, candidate)
- print(besti) #2920
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement