Write code to determine who wins a four-card trick in a game of Spades. Fewest bytes wins.
The input is a string that lists the four cards played in sequence like
TH QC JH 2H (Ten of Hearts, Queen of Clubs, Jack of Hearts, Two of Hearts). A card is given by two characters: a suit from
CDHS and a value from
23456789TJQKA. You are guaranteed that the input is valid and the cards are distinct.
You should output a number 1, 2, 3, or 4 for the winner of the trick. In the example
TH QC JH 2H, the jack of hearts wins the trick, so you should output 3.
Your input and output must be exactly as described, except trailing newlines are optional.
Here are the Spades rules for winning a trick. The winning card is the highest card of the four, with some caveats. Spades is the trump suit, so any spade outranks any non-spade. The suit of the first card played is the lead suit, and only cards of that suit or spades are eligible to win the trick. Cards of the same suit are compared by their values, which are given in increasing order as
TH QC JH 2H 3 KC 5S QS 9C 3 QD 2D TD 5D 1 9S 5D AD QS 4 3D 4C 3H JH 1 9S 4S TS JS 4 5H 9H 2C AD 2 5S 4C 3H QD 1 2H 2S KH AH 2