I am trying to plant a garden. Certain plants are good for some plants and bad for others, and I am trying to find the best order of plants: most adjacent friends and no adjacent foes, as defined in this table:
Num Vegetable Friends Foes 1 Watermelon 7,4,3 8,6 2 Tomatoes 9,8,6,5,1 7 3 Sunflowers 7,6,11 4 Zucchini 9,7,3 5 Eggplant 9,6,2 7,10 6 Cucumbers 9,7,3 8,1 7 Corn 8,6,4,3,1 5,2 8 Cantaloup 7,4,3 6,1 9 Bell peppers6,5,11,10,2 10 Swiss chard 2 5 11 Rhubarb 9,3
Assuming I have one of each plant and they are being planted in a row, how do I sort them (most efficiently) so that I will get the most adjacent friends and no adjacent enemies? There are tools online, but I am trying to understand the thought process and the implementation. Java is a language I know, so that would be the most helpful out of any language, but the concepts are the main point for me.