You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/concept/card-games/.docs/instructions.md
+9-21Lines changed: 9 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,48 +3,39 @@
3
3
Elyse is really looking forward to playing some poker (and other card games) during her upcoming trip to Vegas.
4
4
Being a big fan of "self-tracking" she wants to put together some small functions that will help her with tracking tasks and has asked for your help thinking them through.
5
5
6
-
7
6
## 1. Tracking Poker Rounds
8
7
9
8
Elyse is especially fond of poker, and wants to track how many rounds she plays - and _which rounds_ those are.
10
9
Every round has its own number, and every table shows the round number currently being played.
11
10
Elyse chooses a table and sits down to play her first round. She plans on playing three rounds.
12
11
13
-
14
12
Implement a function `get_rounds(<round_number>)` that takes the current round number and returns a single `list` with that round and the _next two_ that are coming up:
15
13
16
-
17
14
```python
18
15
>>> get_rounds(27)
19
16
[27, 28, 29]
20
17
```
21
18
22
-
23
19
## 2. Keeping all Rounds in the Same Place
24
20
25
21
Elyse played a few rounds at the first table, then took a break and played some more rounds at a second table ... but ended up with a different list for each table!
26
22
She wants to put the two lists together, so she can track all of the poker rounds in the same place.
27
23
28
-
29
24
Implement a function `concatenate_rounds(<rounds_1>, <rounds_2>)` that takes two lists and returns a single `list` consisting of all the rounds in the first `list`, followed by all the rounds in the second `list`:
30
25
31
-
32
26
```python
33
27
>>> concatenate_rounds([27, 28, 29], [35, 36])
34
28
[27, 28, 29, 35, 36]
35
29
```
36
30
37
-
38
31
## 3. Finding Prior Rounds
39
32
40
33
Talking about some of the prior Poker rounds, another player remarks how similarly two of them played out.
41
34
Elyse is not sure if she played those rounds or not.
42
35
43
-
44
36
Implement a function `list_contains_round(<rounds>, <round_number>)` that takes two arguments, a list of rounds played and a round number.
45
37
The function will return `True` if the round is in the list of rounds played, `False` if not:
46
38
47
-
48
39
```python
49
40
>>> list_contains_round([27, 28, 29, 35, 36], 29)
50
41
True
@@ -59,7 +50,6 @@ Elyse wants to try out a new game called Black Joe.
59
50
It's similar to Black Jack - where your goal is to have the cards in your hand add up to a target value - but in Black Joe the goal is to get the _average_ of the card values to be 7.
60
51
The average can be found by summing up all the card values and then dividing that sum by the number of cards in the hand.
61
52
62
-
63
53
Implement a function `card_average(<hand>)` that will return the average value of a hand of Black Joe.
64
54
65
55
```python
@@ -69,16 +59,18 @@ Implement a function `card_average(<hand>)` that will return the average value o
69
59
70
60
## 5. Alternate Averages
71
61
72
-
In Black Joe, speed is important.
73
-
Elyse thinks she can "shortcut" the traditional calculation to get an _average-like_ number by taking the average of the first and last card values in the hand - or by using the "middle" card value (the median) of the hand.
74
-
She is hoping one of these calculations might come close to the average, but be quicker to calculate during game play. She'd like you to create a function to test her theory out.
62
+
In Black Joe, speed is important. Elyse is going to try and find a faster way of finding the average.
75
63
64
+
She has thought of two ways of getting an _average-like_ number:
76
65
77
-
Implement a function `approx_average_is_average(<hand>)` that returns a Boolean.
78
-
The function should return `True` if _one (or both)_ of Elyse's approximations yields the same value as calculating the "full" average of a hand.
79
-
The function should return `False` if _neither_ approximation formula yields the same value as the "full" average.
80
-
For the sake of a simple median, we are going to assume the hand always has an odd number of card values.
66
+
- Take the average of the _first_ and _last_ number in the hand.
67
+
- Using the median (middle card) of the hand.
68
+
69
+
Implement the function `approx_average_is_average(<hand>)`, given `hand`, a list containing the values of the cards in your hand.
81
70
71
+
Return `True` if either _one_`or`_both_ of the, above named, strategies result in a number _equal_ to the _actual average_.
72
+
73
+
Note: _The length of all hands are odd, to make finding a median easier._
82
74
83
75
```python
84
76
>>> approx_average_is_average([1, 2, 3])
@@ -98,7 +90,6 @@ Intrigued by the results of her averaging experiment, Elyse is wondering if taki
98
90
99
91
Implement a function `average_even_is_average_odd(<hand>)` that returns a Boolean indicating if the average of the cards at even indexes is the same as the average of the cards at odd indexes.
100
92
101
-
102
93
```python
103
94
>>> average_even_is_average_odd([1, 2, 3])
104
95
True
@@ -107,16 +98,13 @@ True
107
98
False
108
99
```
109
100
110
-
111
101
## 7. Bonus Round Rules
112
102
113
103
Every 11th hand in Black Joe is a bonus hand with a bonus rule: if the last card you draw is a Jack, you double its value.
114
104
115
-
116
105
Implement a function `maybe_double_last(<hand>)` that takes a hand and checks if the last card is a Jack (11).
117
106
If the the last card **is** a Jack (11), double its value before returning the hand.
0 commit comments