/* * Can you do the maths puzzle for Vietnamese eight-year-olds that has stumped * parents and teachers? * All you need to do is place the digits from 1 to 9 in the the grid. * Easy, right? * * +--+ +--+--+--+ +--+ * | | | | -| | |66| * +--+ +--+--+--+ +--+ * | +| | x| | -| |==| * +--+ +--+ +--+ +--+ * |13| |12| |11| |10| * +--+ +--+ +--+ +--+ * | x| | +| | +| | -| * +--+ +--+ +--+ +--+ * | | | | | | | | * +--+--+--+ +--+--+--+ * | :| | +| | x| | :| * +--+--+--+ +--+--+--+ * * a + 13 * b / c + d + 12 * e - f - 11 + g * h / i - 10 == 66 * * You need to fill in the gaps with the digits from 1 to 9 so that the * equation makes sense, following the order of operations - multiply first, * then division, addition and subtraction last. * * a + ((13 * b) / c) + d + (12 * e) - f - 11 + ((g * h) / i) - 10 == 66 * * Assuming integer division: (13 * b) % c == (g * h) % i == 0 * */ #include #include int main() { int a[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; do { if ((13 * a[1]) % a[2] || (a[6] * a[7]) % a[8] || a[0] + ((13 * a[1]) / a[2]) + a[3] + (12 * a[4]) - a[5] - 11 + ((a[6] * a[7]) / a[8]) - 10 != 66) continue; for (int i = 0; i < 9; ++i) printf("%s%d", i ? "," : "", a[i]); printf("\n"); } while (std::next_permutation(a, a + 9)); }