Last active
January 21, 2020 13:28
-
-
Save RuyiLi/0be2c115e2e0821f76131374ecaa5bf2 to your computer and use it in GitHub Desktop.
Calculating the value of Pi in Julia - Google Code-In
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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