I am supposed to do a score calculator in Java for a dice game that rolls 6 dice (with 6 faces). The score is supposed to be calculated according to a list of options that the user has available. Options are 4,5,...,12. For choice "4", all combinations of dice whose values amount to 4 give points.
Each dice can be selected only once during scoring. It doesn't matter which dice are grouped together as long as their sum is equal to the choice value and the total value of the points is maximised. So for example the roll {1 2 4 2 3 3} gives 12 points if user chooses option "4" ([1 3]+[4]+[2 2]). 11 points ([4 3 3 1]) if user chooses option "11". 12 points if user chooses option "6".
I've tried several ways of calculating this but none gives me correct results in 100% of the cases and I've now been stuck with this for over a day.
My question is what would be a good solution/algorithm int calc(List<Integer> input, int sum)
such that e.g.
calc({6,6,6,6,6,5}, 12)=24
calc({6,6,6,6,6,5}, 11)=11
calc({6,6,6,6,6,5}, 3)=0
calc({6,6,6,6,6,5}, 6)=30
Help much appreciated.