Skip to content

Commit 56206ed

Browse files
committed
added new exercise: camicia
1 parent 689301a commit 56206ed

File tree

4 files changed

+293
-0
lines changed

4 files changed

+293
-0
lines changed
Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
{
2+
"exercise": "beggar-my-neighbour",
3+
"cases": [
4+
{
5+
"uuid": "dca32c31-11ed-49f6-b078-79ab912c1f7b",
6+
"description": "easy card combination",
7+
"property": "findEndGame",
8+
"input": {
9+
"playerA": "--------------------------",
10+
"playerB": "----------AAAAKKKKQQQQJJJJ"
11+
},
12+
"expected": {
13+
"status": "finished",
14+
"cards": 40,
15+
"tricks": 4
16+
}
17+
},
18+
{
19+
"uuid": "1f8488d0-48d3-45ae-b819-59cedad0a5f4",
20+
"description": "easy card combination, inverted decks",
21+
"property": "findEndGame",
22+
"input": {
23+
"playerA": "----------AAAAKKKKQQQQJJJJ",
24+
"playerB": "--------------------------"
25+
},
26+
"expected": {
27+
"status": "finished",
28+
"cards": 40,
29+
"tricks": 4
30+
}
31+
},
32+
{
33+
"uuid": "98878d35-623a-4d05-b81a-7bdc569eb88d",
34+
"description": "mirrored decks",
35+
"property": "findEndGame",
36+
"input": {
37+
"playerA": "-A-A-K-K-Q-Q-J-J----------",
38+
"playerB": "-A-A-K-K-Q-Q-J-J----------"
39+
},
40+
"expected": {
41+
"status": "finished",
42+
"cards": 59,
43+
"tricks": 4
44+
}
45+
},
46+
{
47+
"uuid": "3e0ba597-ca10-484b-87a3-31a7df7d6da3",
48+
"description": "opposite decks",
49+
"property": "findEndGame",
50+
"input": {
51+
"playerA": "-A-A-K-K-Q-Q-J-J----------",
52+
"playerB": "----------J-J-Q-Q-K-K-A-A-"
53+
},
54+
"expected": {
55+
"status": "finished",
56+
"cards": 151,
57+
"tricks": 21
58+
}
59+
},
60+
{
61+
"uuid": "92334ddb-aaa7-47fa-ab36-e928a8a6a67c",
62+
"description": "random decks #1",
63+
"property": "findEndGame",
64+
"input": {
65+
"playerA": "K---J----AK---J-J---------",
66+
"playerB": "--KAQ-A-Q-----Q-K--A-Q-J--"
67+
},
68+
"expected": {
69+
"status": "finished",
70+
"cards": 542,
71+
"tricks": 76
72+
}
73+
},
74+
{
75+
"uuid": "30477523-9651-4860-84a3-e1ac461bb7fa",
76+
"description": "random decks #2",
77+
"property": "findEndGame",
78+
"input": {
79+
"playerA": "-A---QJ-----KA--K---K---K-",
80+
"playerB": "----QJA------JA-Q-JQ------"
81+
},
82+
"expected": {
83+
"status": "finished",
84+
"cards": 327,
85+
"tricks": 42
86+
}
87+
},
88+
{
89+
"uuid": "20967de8-9e94-4e0e-9010-14bc1c157432",
90+
"description": "Kleber 1999",
91+
"property": "findEndGame",
92+
"input": {
93+
"playerA": "---JQ---K-A----A-J-K---QK-",
94+
"playerB": "-J-----------AJQA----K---Q"
95+
},
96+
"expected": {
97+
"status": "finished",
98+
"cards": 5790,
99+
"tricks": 805
100+
}
101+
},
102+
{
103+
"uuid": "9f2fdfe8-27f3-4323-816d-6bce98a9c6f7",
104+
"description": "Collins 2006",
105+
"property": "findEndGame",
106+
"input": {
107+
"playerA": "A-QK------Q----KA-----J---",
108+
"playerB": "-JAK----A--Q----J---QJ--K-"
109+
},
110+
"expected": {
111+
"status": "finished",
112+
"cards": 6913,
113+
"tricks": 960
114+
}
115+
},
116+
{
117+
"uuid": "c90b6f8d-7013-49f3-b5cb-14ea006cca1d",
118+
"description": "Mann and Wu 2007",
119+
"property": "findEndGame",
120+
"input": {
121+
"playerA": "K-KK----K-A-----JAA--Q--J-",
122+
"playerB": "---Q---Q-J-----J------AQ--"
123+
},
124+
"expected": {
125+
"status": "finished",
126+
"cards": 7157,
127+
"tricks": 1007
128+
}
129+
},
130+
{
131+
"uuid": "a3f1fbc5-1d0b-499a-92a5-22932dfc6bc8",
132+
"description": "Nessler 2012",
133+
"property": "findEndGame",
134+
"input": {
135+
"playerA": "----Q------A--K--A-A--QJK-",
136+
"playerB": "-Q--J--J---QK---K----JA---"
137+
},
138+
"expected": {
139+
"status": "finished",
140+
"cards": 7207,
141+
"tricks": 1015
142+
}
143+
},
144+
{
145+
"uuid": "9cefb1ba-e6d1-4ab7-9d8f-76d8e0976d5f",
146+
"description": "Anderson 2013",
147+
"property": "findEndGame",
148+
"input": {
149+
"playerA": "--A-Q--J--J---Q--AJ-K---K-",
150+
"playerB": "-J-------Q------A--A--QKK-"
151+
},
152+
"expected": {
153+
"status": "finished",
154+
"cards": 7225,
155+
"tricks": 1016
156+
}
157+
},
158+
{
159+
"uuid": "d37c0318-5be6-48d0-ab72-a7aaaff86179",
160+
"description": "Rucklidge 2014",
161+
"property": "findEndGame",
162+
"input": {
163+
"playerA": "-J------Q------AAA-----QQ-",
164+
"playerB": "K----JA-----------KQ-K-JJK"
165+
},
166+
"expected": {
167+
"status": "finished",
168+
"cards": 7959,
169+
"tricks": 1122
170+
}
171+
},
172+
{
173+
"uuid": "4305e479-ba87-432f-8a29-cd2bd75d2f05",
174+
"description": "Nessler 2021",
175+
"property": "findEndGame",
176+
"input": {
177+
"playerA": "----K---A--Q-A--JJA------J",
178+
"playerB": "-----KK---------A-JK-Q-Q-Q"
179+
},
180+
"expected": {
181+
"status": "finished",
182+
"cards": 7972,
183+
"tricks": 1106
184+
}
185+
},
186+
{
187+
"uuid": "252f5cc3-b86d-4251-87ce-f920b7a6a559",
188+
"description": "Nessler 2022",
189+
"property": "findEndGame",
190+
"input": {
191+
"playerA": "---AJ--Q---------QAKQJJ-QK",
192+
"playerB": "-----A----KJ-K--------A---"
193+
},
194+
"expected": {
195+
"status": "finished",
196+
"cards": 8344,
197+
"tricks": 1164
198+
}
199+
},
200+
{
201+
"uuid": "b9efcfa4-842f-4542-8112-8389c714d958",
202+
"description": "Casella 2024, first infinite game found",
203+
"property": "findEndGame",
204+
"input": {
205+
"playerA": "---K---Q-KQAJ-----AAJ--J--",
206+
"playerB": "----------Q----KQ-J-----KA"
207+
},
208+
"expected": {
209+
"status": "loop",
210+
"cards": 474,
211+
"tricks": 66
212+
}
213+
}
214+
]
215+
}

exercises/camicia/instructions.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Instructions
2+
3+
In this exercise, you will simulate the classic card game **Beggar-my-neighbour** (*Camicia*).
4+
Your program will receive the initial configuration of two players’ decks and must simulate the game until it ends (or detect if it never does).
5+
6+
## Rules
7+
8+
* The deck is split between **two players**. Each player’s cards are represented as a string (top of the deck = leftmost character).
9+
10+
* Players take turns placing the **top card** of their deck onto a central pile.
11+
12+
* If the card is a **number card** (`-` in this scenario), play simply passes to the other player.
13+
14+
* If the card is a **payment card**:
15+
16+
* `J` → opponent must pay 1 card
17+
* `Q` → opponent must pay 2 cards
18+
* `K` → opponent must pay 3 cards
19+
* `A` → opponent must pay 4 cards
20+
21+
* While paying, if the opponent reveals another payment card, the penalty immediately switches back.
22+
23+
* If the penalty is fully paid without interruption, the player who laid the **last payment card** collects the central pile and places it at the bottom of their deck. That player also starts the next round.
24+
25+
* The game ends when one player has no more cards.
26+
27+
## Example
28+
29+
Here’s a simple example of input and output.
30+
31+
```json
32+
"input": {
33+
"playerA": "--------------------------",
34+
"playerB": "----------AAAAKKKKQQQQJJJJ"
35+
},
36+
"output": {
37+
"status": "finished",
38+
"cards": 40,
39+
"tricks": 4
40+
}
41+
```
42+
43+
### Explanation:
44+
45+
* Player A only has number cards (`-`), so can never defend against a payment card.
46+
* Player B has a long sequence of Aces, Kings, Queens, and Jacks.
47+
* Each court card forces penalties, which Player A cannot counterattack, so Player B repeatedly wins the pile.
48+
* In the end, player B captures his opponent's entire deck by playing 40 cards in just 4 "tricks" (turns in which a deck is collected).
49+
50+
## Your Task
51+
52+
* Parse the two players’ decks from the input.
53+
* Simulate the game following the rules above.
54+
* Return the result as an object with:
55+
56+
* `"status"`: `"finished"` or `"loop"`
57+
* `"cards"`: total number of cards played throughout the game
58+
* `"tricks"`: number of times the central pile was collected

exercises/camicia/introduction.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Introduction
2+
3+
One rainy afternoon, you sit at the kitchen table playing cards with your grandmother.
4+
The game is [Beggar-my-neighbour][bmn], or as she calls it, “Camicia.”
5+
At first it feels like just another friendly match: cards slapped down, laughter across the table, the occasional victorious grin from Nonna.
6+
But as the game drags on, something strange happens. The pile keeps growing. You play card after card, yet the end never seems to come.
7+
8+
You start to wonder: _Will this game ever finish? Or could we keep playing forever?_
9+
10+
Later, driven by curiosity, you search online and to your surprise you discover that what happened wasn’t just bad luck.
11+
You and your grandmother may have stumbled upon one of the longest possible sequences!
12+
Suddenly, you’re hooked. What began as a casual game has turned into a quest: _How long can such a game really last? Can you find a sequence even longer than the one you played at the kitchen table? Perhaps even long enough to set a new world record?_
13+
14+
And so, armed with nothing but a deck of cards and some algorithmic ingenuity, you decide to investigate…
15+
16+
[bmn]: https://en.wikipedia.org/wiki/Beggar-my-neighbour

exercises/camicia/metadata.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title = "Camicia"
2+
blurb = "Simulate the card game and determine whether the match ends or enters an infinite loop."
3+
source = "Beggar-My-Neighbour"
4+
source_url = "https://www.richardpmann.com/beggar-my-neighbour-records.html"

0 commit comments

Comments
 (0)