0 1 1 0
1 0 0 1
1 1 0 0
0 1 1 0
Each row represents which of the houses a person is allowed to be given, and I need an algorithm that figures this out.
In my program, the 'pattern' isn't the same every time (of course), but it will always be possible to solve, e.g. I want the above to output:
2
3
0
1
Which is the only way each person can be given his own house.
I was hoping someone had done something similar before, or is just better at this than me. (The best I would have been able to do would have been something recursive, and I was hoping there was a better way)
Edit: I'm using c++, but I guess it doesn't matter since I could translate from most other languages, or you could use pseudocode.
Edited by Grantax, 25 August 2007 - 04:25 PM.