Advertisement
Houshalter

Chicken Problem

Oct 21st, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.69 KB | None | 0 0
  1. function thing(chickens,l,h)
  2.     return (35-chickens*h)/(l-h)
  3. end
  4. math.randomseed(os.time())
  5. bestErr = math.huge
  6. for i = 1, 100000000 do
  7.     priceBefore = math.ceil(math.random()*100*100)/100
  8.     priceAfter = math.ceil(math.random()*priceBefore*100)/100
  9.     a1 = thing(10,priceBefore,priceAfter)
  10.     a2 = thing(16,priceBefore,priceAfter)
  11.     a3 = thing(26,priceBefore,priceAfter)
  12.     err = math.abs(a1-math.floor(a1))+math.abs(a2-math.floor(a2))+math.abs(a3-math.floor(a3))
  13.     if err < bestErr and (a1>=0) and ((10-a1)>=0) and (a2>=0) and ((16-a2)>=0) and (a3>=0) and ((26-a3)>=0) then
  14.         bestErr = err
  15.         bestPriceBefore = priceBefore
  16.         bestPriceAfter = priceAfter
  17.     end
  18. end
  19. print(bestPriceBefore, bestPriceAfter)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement