Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function prime(n)
- for i = 2, n^(1/2) do
- if (n % i) == 0 then
- return false
- end
- return true
- end
- end
- function getSectors(x, y, turtleAmount)
- totalArea = x*y
- local l = true
- local w = true
- local j = 2
- local m = 2
- if prime(totalArea) == true then
- turtleCountNeeded = 1
- else
- repeat
- if turtleAmount <= j and math.mod(x, j) == 0 then
- l = false
- elseif turtleAmount > j and (x % j) == 0 then
- j=j+1
- l = true
- elseif turtleAmount > j and (x % j) ~= 0 then
- j=j+1
- elseif turtleAmount < j and (x % j) ~= 0 then
- j=j-1
- end
- until l == false
- turtlesPerX = j-1
- repeat
- if turtleAmount < m and (y % m) == 0 then
- w = false
- elseif turtleAmount > m and (y % m) == 0 then
- m = m+1
- w = true
- elseif turtleAmount > m and (y % m) ~= 0 then
- m = m+1
- w = true
- elseif turtleAmount < m and (y % m) ~= 0 then
- m = m-1
- end
- until w == false
- turtlesPerY = m-1
- length = x/turtlesPerX
- width = y/turtlesPerY
- areaPerSector = width*length
- sectorCount = totalArea/areaPerSector
- end
- return length, width, sectorCount
- end
- length, width, sectorCount = getSectors(10, 10, 40)
- print("Amount of sectors: "..sectorCount)
- print("Length per sector: "..length)
- print("Width per sector: "..width)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement