WeChat:lovexc60
Write a function called phazed_group_type that takes the following single argument:
group
A group of cards in the form of a list, each element of which is a 2-character string with the value (drawn from ‘234567890JQKA’) followed by the suit (drawn from ‘SHDC’), e.g. [‘2C’, ‘2S’, ‘2H’] represents a group of three cards, made up of the Two of Clubs, the Two of Spades, and the Two of Hearts.
The function should return a sorted list of integers indicating card combination types as specified below, in the case that group is a valid instance of one or more of the following combinations of cards (and the empty list in the instance that it doesn’t correspond to any valid card combination). Note that the combination of cards in its entirety must satisfy the requirements of the combination definition, such that [‘2C’, ‘2C’, ‘4C’, ‘KC’, ‘9C’, ‘AH’, ‘JC’] is not a valid set of three cards of the same value, e.g., as it is made up of seven cards (despite the fact that it contains [‘2C’, ‘2C’, ‘AH’] which is a valid set of three cards of the same value).
1
A set of three cards of the same value, e.g. [‘2C’, ‘2S’, ‘2H’] represents a set of three Twos. Note that the set may include Wilds, but must include at least two “natural” cards (i.e. non-Wild cards), which define the value. Note also that the sequence of the cards is not significant for this group type.
2
A set of seven cards of the same suit, e.g. [‘2C’, ‘2C’, ‘4C’, ‘KC’, ‘9C’, ‘AH’, ‘JC’] represents a set of seven Clubs. Note that the set may include Wilds (as we see in our example, with the Ace of Hearts), but must include at least two “natural” cards (i.e. non-Wild card), which define the suit. Note also that the sequence of the cards is not significant for this group type.
3
A set of four cards of the same value, e.g. [‘4H’, ‘4S’, ‘AC’, ‘4C’] represents a set of four Fours. Note that the set may include Wilds (as we see in our example, with the Ace of Clubs), but must include at least two “natural” cards (i.e. non-Wild cards), which define the value. Note also that the sequence of the cards is not significant for this group type.
4
A run of eight cards, e.g. [‘4H’, ‘5S’, ‘AC’, ‘7C’, ‘8H’, ‘AH’, ‘0S’, ‘JC’] represents a run of eight cards. Note that the card combination may include Wilds (as we see in our example, with the Ace of Clubs standing in for a Six and the Ace of Hearts standing in for a Nine), but must include at least two “natural” cards (i.e. non-Wild cards). Note also that the sequence of the cards is significant for this group type, and that [‘4H’, ‘5S’, ‘AC’, ‘8H’, ‘7C’, ‘AH’, ‘0S’, ‘JC’], e.g., is not a valid run of eight, as it is not in sequence.
5
A run of four cards of the same colour, e.g. [‘4H’, ‘5D’, ‘AC’, ‘7H’] represents a run of four Red cards. Note that the card combination may include Wilds (as we see in our example, with the Ace of Clubs standing in for a Red Six), but must include at least two “natural” cards (i.e. non-Wild cards), which define the colour. Note also that the sequence of the cards is significant for this group type, and that [‘4H’, ‘5D’, ‘7H’, ‘AC’] is not a valid run of four cards of the same colour, as it is not in sequence.
6
A 34-accumulation of cards, that is an accumulation of cards totalling 34 in value, e.g. [‘KS’, ‘0D’, ‘8C’, ‘3S’]. Note that for accumulations, Aces do not function as Wilds, and simply take the value 1.
7
A 34-accumulation of cards of the same colour, that is an accumulation of cards of the same colour totalling 34 in value, e.g. [‘KS’, ‘0C’, ‘8C’, ‘3S’]. Note that for accumulations, Aces do not function as Wilds, and simply take the value 1.
>>> phazed_group_type([‘2C’, ‘2S’, ‘2H’])
>>> phazed_group_type([‘2C’, ‘2C’, ‘4C’, ‘KC’, ‘9C’, ‘AH’, ‘JC’])
>>> phazed_group_type([‘4H’, ‘4S’, ‘AC’, ‘4C’])
>>> phazed_group_type([‘4H’, ‘5S’, ‘AC’, ‘7C’, ‘8H’, ‘AH’, ‘0S’, ‘JC’])
>>> phazed_group_type([‘4H’, ‘5D’, ‘AC’, ‘7H’])
>>> phazed_group_type([‘KS’, ‘0D’, ‘8C’, ‘3S’])
>>> phazed_group_type([‘KS’, ‘0C’, ‘8C’, ‘3S’])
>>> phazed_group_type([‘2C’, ‘2C’, ‘4C’, ‘KC’, ‘9C’, ‘AS’, ‘3C’])
[2, 6, 7]
>>> phazed_group_type([‘4H’, ‘5D’, ‘7C’, ‘AC’])