A generalized solution might go something like this:
startingList = {1, 9, 3, 7, 8};
allowedSums = {2}; (* to get pairs only *)
desiredSum = 10;
(* trim duplicates created by IntegerPartitions *)
okMinimumSolution =
Select[minimumSolution, DeleteDuplicates[#] == # &];
maximalSolution = Flatten[Permutations[#] & /@ okMinimumSolution, 1];
The reason I say a generalized solution is imagine we have this:
startingList = {1, 9, 3, 7, 8, 12, 15};
allowedSums = {2, 3};(*to get solutions between 2 & 3 values*)
desiredSum = 17;
Running the code above on this new startingList and allowedSums gives this:
(* {{8, 9}, {9, 8}, {7, 9, 1}, {7, 1, 9}, {9, 7, 1}, {9, 1, 7}, {1, 7, 9}, {1, 9, 7}} *)
Now the point of this being generalized is clear. My assumption is that the initial list had no duplicates and that we have to "fix up" the result of IntegerPartitions since it may choose multiples of the given set and I said we don't want this.
Hope this is helpful to someone. It was fun to think of how to generalize the solution.
Permutations[]
? $\endgroup$