Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Need an algorithm


  • Please log in to reply

#1
Grantax

Grantax

    Member

  • Member
  • PipPip
  • 79 posts
So let's say I have 4 persons and 4 houses (this isn't exactly the case in my code, and the number also has to be variable), and I have a map over which persons can be living in each of the houses:

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.

  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP