A higher resolution is required to access the IDE
- 13
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
It's two years into the apocalypse and you've been living alone in a bunker. The only soul you can talk to is an AI bot named Nobs. To pass the time you play games against Nobs. But he only knows how to play Solitaire and Minesweeper which you've grown tired of. You decide to teach him your favorite pre-apocalypse game, Cribbage.Cribbage is a two-player card and board game where you make combinations to count points and get to the target before your opponent.
See here for all the details: https://en.wikipedia.org/wiki/Cribbage and here for the rules: https://en.wikipedia.org/wiki/Rules_of_cribbage.
Using a stack of security keycards as a deck, toothpicks for pegs, and an old pizza box for a board you start to play against Nobs. At first, Nobs is incredibly bad at playing since he has no idea how to play and simply discards at random into the crib. You decide that the only way Nobs will ever be a challenge to you is if you teach him the rules for scoring hands so that he can best decide which cards to keep.
Write the algorithm that Nobs should use to score his hand.
Scoring:
You hold 4 cards in your hand and a fifth common starter card is cut and included when scoring your hand.
Fifteens: 2 points for every distinct group of cards whose totals adds up to 15, (
Runs: 3 or more consecutive cards by rank, 1 point for each card. Ex:
Pairs: 2 points for every distinct pair of cards with identical ranks. This means that a triplet gives 6 points and a quadruplet 12 points. Ex:
Flushes: 4 points if all 4 cards in your hand are of the same suit, 5 points if the starter card is also the same suit. Ex:
His nobs: 1 point if you have a
29 Hand: All five 5's and the
Ex:
Add it all up and you get 29! The chances to get a twenty-nine hand are 1 in 216580.
Input
Line 1: An integer N for the number of hands to score
N Lines: 5 Space-separated values describing the cards in the hand (The first 4 cards for the player, the 5th is the starter card).
Cards are input as a two-character string. The first character is the card's rank (A , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , T , J , Q , K ) and the second is its suit (H earts, D iamonds, C lubs, S pades). A has a value of 1, T , J , Q , K are all 10, the rest are all face value.
N Lines: 5 Space-separated values describing the cards in the hand (The first 4 cards for the player, the 5th is the starter card).
Cards are input as a two-character string. The first character is the card's rank (
Output
N Lines: The score for the given hand.
Constraints
1 ≤ N ≤ 10
Example
Input
5 7H 8D TS 2H 4C 5C TD KS 2H 4C 6H AS 9C TS KH 2C TS 3D 6S 8C 2C TS 3D QH 8C
Output
2 4 2 2 4
A higher resolution is required to access the IDE