As a kid, I used to play the card game "golf" a lot. Your challenge, should you choose to accept it, is to calculate the score of a golf hand. Since there are over 9000 variations on this card game1, we will go with the rules I remember playing.
Rules (of the game)
You end a round with 6 cards, and you want as few points as possible.
Jokers are not used.
Aces and 2s are worth -1, and -2 points respectively.
Jacks and Kings are both worth 0 points.
Cards from 3 to 10 are worth face value. However, these are cancelled when you pair them off. For example, a 5 is worth 5 points, but two 5s are worth zero. Three 5s are worth 5 points, (since the first 2 are paired off, but the 3rd is not.) and four 5s are worth 0 (since it makes 2 pairs).
Queens are worth 15 points. Queens cannot be cancelled, e.g. 2 queens are worth 30 points.
Rules (of the challenge)
Input will be an array of integers, or 6 individual integers. Whichever one you prefer. 1 represents an ace, 2-10 represents 2-10, and Jack, Queen, and King represents 11, 12, and 13. Output is the score of the hand according to the rules above. You can safely assume that all inputs are valid, e.g. no number appears more than 4 times, and all numbers are in the range [1, 13]
. Input and output can be in any reasonable format.
Test IO:
[11, 10, 3, 1, 2, 2] --> 8
[4, 5, 5, 3, 8, 7] --> 22
[2, 2, 2, 2, 1, 1] --> -10 (The lowest score possible)
[12, 12, 12, 12, 10, 9] --> 79 (The highest score possible)
[9, 9, 9, 9, 11, 1] --> -1
[8, 8, 8, 8, 11, 13] --> 0
[10, 9, 3, 7, 12, 2] --> 42
[1, 2, 3, 4, 5, 6] --> 15
[10, 9, 2, 3, 4, 1] --> 23
[10, 3, 12, 3, 7, 12] --> 47
Shortest answer in bytes wins!
1not really, but there are a lot of variations.