Advertisement
Blazuno

Untitled

Nov 3rd, 2021 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1.  
  2.  
  3. function prime(n)
  4. for i = 2, n^(1/2) do
  5. if (n % i) == 0 then
  6. return false
  7. end
  8. return true
  9. end
  10. end
  11.  
  12. function getSectors(x, y, turtleAmount)
  13. totalArea = x*y
  14. local l = true
  15. local w = true
  16. local j = 2
  17. local m = 2
  18. if prime(totalArea) == true then
  19. turtleCountNeeded = 1
  20. else
  21. repeat
  22. if turtleAmount <= j and math.mod(x, j) == 0 then
  23. l = false
  24. elseif turtleAmount > j and (x % j) == 0 then
  25. j=j+1
  26. l = true
  27. elseif turtleAmount > j and (x % j) ~= 0 then
  28. j=j+1
  29. elseif turtleAmount < j and (x % j) ~= 0 then
  30. j=j-1
  31. end
  32.  
  33. until l == false
  34. turtlesPerX = j-1
  35.  
  36. repeat
  37. if turtleAmount < m and (y % m) == 0 then
  38. w = false
  39. elseif turtleAmount > m and (y % m) == 0 then
  40. m = m+1
  41. w = true
  42. elseif turtleAmount > m and (y % m) ~= 0 then
  43. m = m+1
  44. w = true
  45. elseif turtleAmount < m and (y % m) ~= 0 then
  46. m = m-1
  47. end
  48. until w == false
  49. turtlesPerY = m-1
  50. length = x/turtlesPerX
  51. width = y/turtlesPerY
  52. areaPerSector = width*length
  53. sectorCount = totalArea/areaPerSector
  54. end
  55. return length, width, sectorCount
  56. end
  57.  
  58. length, width, sectorCount = getSectors(10, 10, 40)
  59.  
  60. print("Amount of sectors: "..sectorCount)
  61. print("Length per sector: "..length)
  62. print("Width per sector: "..width)
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement