One of the things that makes contract bridge very interesting is its highly complicated "artificial" meta game. This system of scoring hands is a small part of it.
Bridge is a trick-taking card game. Each player gets a hand of 13 cards, and the game starts with the bidding. The bidding determines how the rest of the game plays, and so is a crucial part of it. In order to ensure that you and your partner do not bid too high (or too low), this artificial scoring system was developed to tell you how good your hand is.
Here's a sample hand:
S:KQT5 H:J72 D:965 C:AK8
The S, H, D, C represent the suits (spades, hearts, diamonds and clubs) and the rest are the cards in those suits. So this hand has a queen of spades (Q), king of spades (K), ten of spades (T), five of spades, jack of hearts, seven of hearts, etc.
The scoring system works as follows:
- You get 4 points for every ace (A) you have, 3 points for every king (K), 2 points for every queen (Q) and 1 point for every jack (J). No other cards give points.
- Every card after the fourth in a suit gives you 1 point. So if you have six hearts, you'd get 2 points.
- A suit where you only have 2 cards gives you 1 point (this is a doubleton). A suit where you have just 1 card gives you 2 points (this is a singleton). If you have no cards in a certain suit, you get 3 points (this is a void). (Usually these are only counted once you've agreed on a suit with your partner, but I'm including them to make the challenge more interesting.)
So, the above hand has 13 points.
Given a bridge hand in the format shown above, calculate how many points the hand has. The suits will always be listed in the order spades, hearts, diamonds and clubs, and the cards will always be sorted in the order A, K, Q, J, T, 9 - 2.
Sample Inputs and Outputs
S:KQT5 H:J72 D:965 C:AK8 \-> 13 S:AKQT6 H:54 D:J83 C:732 \-> 12 S: H:KQT8754 D:A86 C:432 \-> 15 S:9876 H:843 D:652 C:432 \-> 0 S:AKQT5 H:AQJ6 D:Q3 C:AK \-> 28
This is code-golf, so shortest code in bytes wins.