in reply to Gift Exchange Code
General bin packing problem. Instead of checking if the pair of people "fit", however, you test against your own constraints - they are not SO. If not, pair them, move the pair into the bin, and move on with the remaining people.
Some pseudocode
global results = (); function match (people) { if (people.empty) { return SUCCESS } $x = people.pop; foreach $y (people) { if (validpair($x, $y) { if (match(people.remove($y)) == SUCCESS) { results.push( {$x, $y} ); return SUCCESS; } } } return FAILURE; }
--MidLifeXis
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Gift Exchange Code
by JadeNB (Chaplain) on Oct 29, 2008 at 21:41 UTC | |
by MidLifeXis (Monsignor) on Oct 30, 2008 at 17:23 UTC | |
|
Re^2: Gift Exchange Code
by gloryhack (Deacon) on Oct 30, 2008 at 10:26 UTC | |
by MidLifeXis (Monsignor) on Oct 30, 2008 at 16:43 UTC | |
by JadeNB (Chaplain) on Oct 30, 2008 at 19:16 UTC | |
by MidLifeXis (Monsignor) on Oct 30, 2008 at 20:16 UTC |