Skip to content

Instantly share code, notes, and snippets.

@RuyiLi
Last active January 21, 2020 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RuyiLi/0be2c115e2e0821f76131374ecaa5bf2 to your computer and use it in GitHub Desktop.
Save RuyiLi/0be2c115e2e0821f76131374ecaa5bf2 to your computer and use it in GitHub Desktop.
Calculating the value of Pi in Julia - Google Code-In
# Author: Ruyi Li (weCryOpen)
function mypi(n::Int)::Float
total_sum::Float = 0
for i = 1:n
total_sum += 1 / (i * i)
end
(total_sum * 6) ^ 0.5
end
# Author: Ruyi Li (weCryOpen)
function approximate_pi(accuracy)
function helper(acc)
acc == 1 && return 1
1 / acc ^ 2 + helper(acc - 1)
end
(helper(accuracy) * 6) ^ 0.5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment