Advertisement
moomoomoo309

makeCuboidsOfVolume

Jun 8th, 2016
287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.56 KB | None | 0 0
  1. function makeCuboidsOfVolume(a,b,c,volume)
  2.   local volume=volume or 4096
  3.   local minLen=math.floor(volume^(1/3))
  4.   local min=math.ceil(a/minLen)*math.ceil(b/minLen)*math.ceil(c/minLen)
  5.   local solution={x=minLen,y=minLen,z=minLen,vol=volume,num=min}
  6.   for x=1,math.min(a,volume) do
  7.     for y=1,math.min(b,volume/x) do
  8.       local z=math.floor(volume/(x*y))
  9.       local num=math.ceil(a/x)*math.ceil(b/y)*math.ceil(c/z)
  10.       if (num < min) then
  11.         min=num
  12.         solution={x=x,y=y,z=z,vol=x*y*z,num=min}
  13.       end
  14.     end
  15.   end
  16.   return solution
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement