Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. const PHI = (Math.sqrt(5) + 1) / 2
  2.  
  3. function divisor (n) {
  4. if (n === 0) return Math.sqrt(2 + PHI)
  5.  
  6. var last = divisor(n - 1)
  7. return Math.sqrt(2 + last)
  8. }
  9.  
  10. function pi (n) {
  11. if (n === 0) return 5 / PHI
  12.  
  13. var last = pi(n - 1)
  14. return last * 2 / divisor(n)
  15. }
  16.  
  17. console.log(pi(50))
  18. //=> 3.1415926535897927
  19.  
  20. console.log(Math.PI)
  21. //=> 3.141592653589793
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement