My girlfriend gave me a

puzzle calendar for Christmas. Great fun every day. But some of them I can't figure out. Math problems are easy, but those where you have to find, combine, complete etc. English words often are too tough for me. I wouldn't give up and look up the solutions. I'll write a program to solve those riddles. You might think of this doing it not the way intended, I'll respond I'm just using computers the way they are intended.

Here we go with the first puzzle:

Given a matrix with the following equations. Fill in the fields a to i with the numbers 1 to 9. Evaluate the mathematical operations in the order of appearance, ignoring common operation ordering rules.

a + b / c = 2

- + *

d * e / f = 9

+ / /

g * h - i = 1

= = =

5 3 4

I decided to go with a brute-force attack here:

1. create all permutations of the numbers 1 to 9

2. check if above equations are true, if so print out current permutation

Since I use C/C++ a lot lately it's the language of my choice. Also I write most of these during bus rides or other idling periods, so expect dirty code.

Check out the recursive code for the permutations.

matrixtester.cpp