-
-
Save nabijaczleweli/0f4c2f74ae5744e4f18d 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
#include <iostream> | |
#include <ctime> | |
int main() { | |
const auto pentagonal_function = [](double n) -> double { return (n * ((3 * n) - 1)) / 2; }; | |
const auto hexagonal_function = [](double n) -> double { return n * ((2 * n) - 1); }; | |
auto pent_index = 0u; | |
auto hex_index = 0u; | |
auto solution_count = 1u; | |
std::clock_t start = std::clock(); | |
while(true) { | |
const auto pent = pentagonal_function(pent_index); | |
const auto hex = hexagonal_function(hex_index); | |
if(pent < hex) | |
++pent_index; | |
else if(pent > hex) | |
++hex_index; | |
else if(pent == hex) { | |
++solution_count; | |
++pent_index; | |
std::cout << "solution #" << solution_count << ":\n pent_index: " << pent_index << "\n hex_index: " << hex_index << "\n y: " << pent | |
<< "\n elapsed: " << ((std::clock() - start) / (double)CLOCKS_PER_SEC) << "s\n\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment