Advertisement
Guest User

Simulate lollipop farming

a guest
Sep 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. import math
  2.  
  3. def lps(planted):
  4.     """Lollipops per second."""
  5.     return math.ceil(100*(1-math.exp(-(planted-20)/5000)))
  6.  
  7.  
  8.  
  9. ###########
  10. # The question is, what is the optimal number of lollipops to plant so that we can reach 5000 lollipops on-hand?
  11. # I think this is a Golden Mean Bisection problem.
  12. def plantuntil(intialPlanted, untilPlanted, mult=3, pops=0):
  13.     seconds = 0
  14.     lollipops = pops
  15.     planted = intialPlanted
  16.     while planted < untilPlanted:
  17.         seconds += 1
  18.         lollipops += lps(planted)*mult
  19.         nowPlant = min(lollipops, untilPlanted - planted)
  20.         lollipops -= nowPlant
  21.         planted += nowPlant
  22.     while lollipops < 5000:
  23.         seconds += 1
  24.         lollipops += lps(planted)*mult
  25.     return seconds
  26.  
  27. initialPlanted = 1554
  28. initialOwned = 2673
  29. mult = 3*3
  30. best = 1000
  31. besti = 0
  32. for i in range(initialPlanted,5000):
  33.     candidate = plantuntil(initialPlanted, i, mult=mult, pops=initialOwned)
  34.     if candidate <= best:
  35.         best = candidate
  36.         besti = i
  37.         #print(i, candidate)
  38.  
  39. print(besti) #2920
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement