Last active
November 9, 2018 16:51
-
-
Save nikhedonia/6ddfa7f79638c0cefaae4c9fe915ecc7 to your computer and use it in GitHub Desktop.
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
double golden(double epsilon=0.00001) { | |
int a = 0; | |
int b = 1; | |
double ratio = 0; | |
while (1) { | |
tie(a, b) = tuple{b, a+b}; | |
auto delta = b / (double)a - ratio; | |
ratio = b / (double)a; | |
if ( abs(delta) < epsilon ) | |
return ratio; | |
} | |
} | |
int main() { | |
cout << golden() << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment