Advertisement
CubitGames

Calculate PI in less than 20 lines of code.

Sep 7th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.39 KB | None | 0 0
  1. done = false
  2. -- The algorithm will be ran 1/2 of the amount variable.
  3. amount = 1000
  4. x = 3
  5. numpi = 1
  6. while x < amount do
  7. numpi = numpi - 1/x
  8. x = x + 2
  9. numpi = numpi + 1/x
  10. x = x + 2
  11. print(numpi * 4)
  12. end
  13. if x > amount and done == false then
  14. numpi = numpi * 4
  15. print(numpi)
  16. print("Depending on how big the 'amount' variable is, is how accurate PI is")
  17. done = true
  18. end
  19. stop = io.read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement