Rullete
Time limit2sMemory limit512 MB
Given five cards, apply fourteen ordered rules that modify a hand value using suit counts, ranks, divisors, primes, and bit counts, then print the final value.
- Level
Medium4 of 10
- Topics
- Simulation, Implementation, Math, Number theory
- Solved
- No attempts yet
Problem
Binary Casino has set up a new department to attract families with children. One of its first tasks is to design a game for children that will not be too hard to play. The result of a week of hard work is a game called Rullete (sic!).
Each player gets a hand of 5 cards. The cards in the hand are ordered as first, second, ..., fifth. Each card is described by a rank and a suit. A card's rank is one of 2, 3, ..., 10, J, Q, K, A and its suit is one of D, H, C, S (Diamonds, Hearts, Clubs, Spades). Cards 2 through 10 score their rank, and J, Q, K, A all score 10. A player's hand starts with a value equal to the sum of the scores of its cards. The value then changes according to the game rules. To make the croupier's life easier, your task is to compute the final value of the hand after all of the following fourteen rules are applied in the given order:
- If the hand has at least 4 cards, add 1 to the value. Also add to the value the product of the number of J's in the hand and the score of the first card in the hand.
- If the hand has at least 2 cards of the same suit, multiply the value by 2.
- If the hand has at least one card of each suit, multiply the value by 2.
- If the number of black cards (Clubs and Spades) and the number of red cards (Hearts and Diamonds) in the hand differ, add the absolute value of the difference to the value.
- If the value is currently even, add all positive integer divisors of the value (including 1 and the value itself) to the value.
- If the hand has exactly 4 cards of rank 7, subtract 112 from the value.
- If the value is currently non-negative, add the score of the lowest-scoring card in the hand to the value.
- If the value is currently negative, multiply the value by −1.
- If the hand has at least 3 cards of suit Diamond, add 1 to the value, then simultaneously swap the ranks of all 6's to 9's, all 9's to 6's, all 2's to 5's, and all 5's to 2's in the hand.
- If the hand has a straight, add five times the number of A's in the hand to the value.
- If the value has been changed by more than 8 rules so far, add the number of 1 bits in the binary representation of the value to the value.
- If the hand has at least one card of rank 2, apply the last rule that changed the value once more (then continue with rule 13).
- If the hand has at least one card of rank 2, add the product of all distinct superfactors of the value to the value. A superfactor is a prime raised to the highest integer power that divides the value evenly.
- If the value is 674, you win!
A straight is a set of any 5 consecutive cards in the order: 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A.
Input
The input is a single line with five space-separated card descriptions, each consisting of a card rank immediately followed by its suit.
Output
Output the score after applying all of the rules.