fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main()
  5. {
  6. int numbers[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  7.  
  8. int tested_combination_count = 0;
  9. int total_permutation_count = 0;
  10. int last_blue = 0;
  11. do
  12. {
  13. int green = numbers[0];
  14. int yellow = numbers[1];
  15. int purple = numbers[2];
  16. int orange = numbers[3];
  17. int red = numbers[4];
  18. int blue = numbers[5];
  19.  
  20. ++total_permutation_count;
  21. if (last_blue == blue) {
  22. continue;
  23. }
  24. last_blue = blue;
  25. ++tested_combination_count;
  26. if (purple * 10 + green == green * yellow
  27. && purple * 10 + orange == red * red
  28. && yellow * 10 + orange == red * blue
  29. && red * 10 + green == green * blue) {
  30. std::cout << green << " " << yellow << " " << purple << " "
  31. << orange << " " << red << " " << blue << std::endl;
  32. }
  33. } while (std::next_permutation(std::begin(numbers), std::end(numbers)));
  34. std::cout << "Combination tested:" << tested_combination_count
  35. << " on a total of " << total_permutation_count << std::endl;
  36. }
Success #stdin #stdout 0.01s 15232KB
stdin
Standard input is empty
stdout
5 3 1 6 4 9
Combination tested:151192 on a total of 3628800