Created
June 2, 2012 01:33
-
-
Save JamesMcNellis/2856084 to your computer and use it in GitHub Desktop.
Bill Teh Lizard's Challenge
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 <algorithm> | |
#include <array> | |
#include <functional> | |
#include <iostream> | |
#include <iterator> | |
#include <numeric> | |
#include <vector> | |
typedef std::array<int, 9> result; | |
typedef std::vector<result> results; | |
auto check(results& rs, int a0, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) -> void | |
{ | |
result r = { a0, a1, a2, a3, a4, a5, a6, a7, a8 }; | |
if (std::accumulate(begin(r), end(r), 0, std::plus<int>()) != 45) | |
return; | |
if (std::accumulate(begin(r), end(r), 1, std::multiplies<int>()) != 362880) | |
return; | |
std::sort(begin(r), end(r)); | |
if (std::find(begin(rs), end(rs), r) != end(rs)) | |
return; | |
std::copy(begin(r), end(r), std::ostream_iterator<int>(std::cout, ",")); | |
std::cout << std::endl; | |
rs.push_back(r); | |
} | |
int main() | |
{ | |
results rs; | |
for (int a0(0); a0 < 10; ++a0) | |
for (int a1(0); a1 < 10; ++a1) | |
for (int a2(0); a2 < 10; ++a2) | |
for (int a3(0); a3 < 10; ++a3) | |
for (int a4(0); a4 < 10; ++a4) | |
for (int a5(0); a5 < 10; ++a5) | |
for (int a6(0); a6 < 10; ++a6) | |
for (int a7(0); a7 < 10; ++a7) | |
for (int a8(0); a8 < 10; ++a8) | |
check(rs, a0, a1, a2, a3, a4, a5, a6, a7, a8); | |
} | |
// Output: | |
// 1,2,3,4,5,6,7,8,9, | |
// 1,2,4,4,4,5,7,9,9, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment