Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Need an algorithm

  • Please log in to reply




  • 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:
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


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