-
-
Save rajesh-scribbledata/19fc5d482dea647da7870f5bc9af3d21 to your computer and use it in GitHub Desktop.
Julia Ramanujan Approximation for Pi
This file contains hidden or 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
| using Core: BigInt | |
| using Base: Int64, Float64 | |
| function fact(n::BigInt) | |
| if n <=1 return 1 end | |
| return n * fact(n-1) | |
| end | |
| println(fact(12)) | |
| function ramanujan_approximation(max_k::BigInt) | |
| constant = 2*sqrt(2) / 9801 | |
| val::Float64 = 0 | |
| for k in 0:max_k | |
| iteration::Float64 = (fact(4*k) * (1103 + 26390*k)) / (fact(k)^4 * 396^(4*k) ) | |
| val += iteration | |
| end | |
| return (constant * val) | |
| end | |
| onebypi = ramanujan_approximation(2) | |
| println(onebypi, " ", 1/onebypi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment