Created
November 29, 2013 05:28
-
-
Save kinchungwong/7701952 to your computer and use it in GitHub Desktop.
This Fibonacci implementation is part of a compare-and-contrast with this other Fibonacci implementation: https://gist.github.com/kinchungwong/7700777 Technically speaking, this version has 3 essential semicolons, while the other implementation (300 lines of commented code) has 46 essential semicolons.
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
#include <iostream> | |
// Technically The First Line of Code - by semicolon counting. | |
template <int N> | |
struct Fibonacci | |
: std::integral_constant< | |
int, | |
Fibonacci<N - 1>::value + Fibonacci<N - 2>::value | |
> | |
{}; | |
// Technically The Second Line of Code. | |
template <> struct Fibonacci<0> : std::integral_constant<int, 1> {}; | |
// Technically The Third Line of Code. | |
template <> struct Fibonacci<1> : std::integral_constant<int, 1> {}; | |
// The main function is totally irrelevant. | |
// Not included in the lines of code. | |
// (If you must ask - semicolons in comments don't count.) | |
int main() | |
{ | |
std::cout << "Fibonacci<0> : " << Fibonacci<0>::value << std::endl; | |
std::cout << "Fibonacci<1> : " << Fibonacci<1>::value << std::endl; | |
std::cout << "Fibonacci<2> : " << Fibonacci<2>::value << std::endl; | |
std::cout << "Fibonacci<3> : " << Fibonacci<3>::value << std::endl; | |
std::cout << "Fibonacci<4> : " << Fibonacci<4>::value << std::endl; | |
std::cout << "Fibonacci<5> : " << Fibonacci<5>::value << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment