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
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
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…
0 commit comments