I have a pretty hard problem to solve here, and I have no idea how to start. I have X kind of fruits and 5 colors (let's say
Purple). Each fruit can be available in several colors (but in at least 1). How can I find each combination, when I need exactly 1 fruit of each color but no fruit twice (so there will always be bought exaclty 5 fruits in exactly 5 different colors)?
- Pears are available in [Red, Green, Yellow]
- Apples are available in [Red, Green]
- Plums are available in [Purple]
- Grapes are available in [Red, Green, Purple]
- Bananas are available in [Blue, Yellow]
Since bananas are the only fruit available in
Blue, it's already sure, that bananas will be bought in
Blue, and not in
These would be the solution for this list:
No other combination is possible here. Is there any algorithm to do this with a dynamic list, which may also have more than 5 fruits?
I know, it's a pretty hard problem, but maybe someone has a simple solution for it.