Advertisement
Guest User

Calculator

a guest
May 17th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. -- Starting Parameters
  2. local var = {" X ", " Y ", " Z "}
  3. local jump = 1
  4. local origin = {}
  5. local dest = {}
  6. local disp = {}
  7. local minjump = {18, 8, 13}
  8. local maxjumpdistance = 100
  9. local maxjump = {}
  10. local jumpdist = {}
  11. local jumplog = {}
  12. for i = 1, 3 do
  13.   maxjump[i] = minjump[i] + maxjumpdistance
  14. end
  15.  
  16. -- Determining Journey
  17. for t = 1, 3 do
  18.   term.setCursorPos(1,t)
  19.   term.write("Enter" .. var[t] .. "coord of origin: ")
  20.   origin[t] = read()
  21. end
  22.   term.clear()
  23. for t = 1, 3 do
  24.   term.setCursorPos(1,t)
  25.   term.write("Enter" .. var[t] .. "coord of destination")
  26.   dest[t] = read()
  27. end
  28. term.clear()
  29. for t = 1,3 do
  30.   disp[t] = dest[t] - origin[t]
  31. end
  32.  
  33. -- Calculating Jumps
  34. while disp ~= {0, 0, 0} do
  35.   for t = 1, 3 do
  36.     fctr = math.abs(disp[t])/disp[t]
  37.     jumpdist[t] = fctr*math.min(maxjump[t],math.abs(disp[t]))
  38.     if jumpdist[t] ~= 0 and math.abs(jumpdist[t]) < minjump[t] then
  39.       jumpdist[t] = fctr*(math.abs(disp[t]) + minjump[t])
  40.     end
  41.     disp[t] = disp[t] - jumpdist[t]
  42.   end
  43.     print(jumpdist[1] .. ", " .. jumpdist[2] .. ", " .. jumpdist[3])
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement