We will represent any list of cards, such as cards in the player's hand, played cards or discarded cards as a list of tuples with two elements. The first element of a tuple is a character corresponding to the card color:
R -- Red
B -- Blue
Y -- Yellow
G -- Green
W -- White.
The second element is the card value. It is a number from 1 to 5.
An example of a list: [("R", 1), ("R", 4), ("Y", 2), ("W", 1)]
We need to be able to encode and decode a list of cards as a string, just concatenating the tuple components one by one, without any delimiters. The example given above will encode as "R1R4Y2W1". In such string, the i-th card will take positions i2 and i2+1, the odd positions will be taken by the card colors and the even positions will be taken by the card values.
We will represent any list of cards, such as cards in the player's hand, played cards or discarded cards as a list of tuples with two elements. The first element of a tuple is a character corresponding to the card color:
The second element is the card value. It is a number from 1 to 5.
An example of a list:
[("R", 1), ("R", 4), ("Y", 2), ("W", 1)]
We need to be able to encode and decode a list of cards as a string, just concatenating the tuple components one by one, without any delimiters. The example given above will encode as "R1R4Y2W1". In such string, the i-th card will take positions i2 and i2+1, the odd positions will be taken by the card colors and the even positions will be taken by the card values.
You need to write functions
and
that will encode and decode a list of cards to/from strings.
Please don't forget to write unit tests for these functions.