-
-
Notifications
You must be signed in to change notification settings - Fork 557
Add new exercise: camicia #2581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
56206ed
60e92fd
d916018
fef5398
e772c42
bb05688
1a000e2
b594c8c
6406758
cdc0aa4
2b0e18f
87bc176
58c1370
d83bde2
2e1b1ef
ae53762
1b21ff5
7ad115e
297ccc4
b2ea69b
c179aeb
02701c8
8d04367
b1b0759
38ce1f3
c151e85
3f09d79
a2ae162
468c807
d4cde54
b1c23b7
6b01ea9
e93651c
bb0f154
c1c04e7
385fc5a
9d8dd23
9c22029
6379ac0
3484c45
527b4a8
320180d
a11753e
7af9552
24b2a6a
887d8a6
a01a403
031ce05
6fe5eff
8de18f1
5dfdead
9714913
8ce43e1
4ec0c04
4a94ae3
96faee9
fb47d80
2926395
2eaa304
953e6c4
49f6441
b65f34e
8b05dee
8f6f0a6
20d6dd5
410d1a5
c85a598
b376f59
a0a8aa6
38e68ef
5194d7e
420da81
d36b84c
58434a9
5d56e6a
78aabec
552e3d1
fe234fe
2cb4341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| { | ||
| "exercise": "camicia", | ||
| "cases": [ | ||
| { | ||
| "uuid": "dca32c31-11ed-49f6-b078-79ab912c1f7b", | ||
| "description": "easy card combination", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "--------------------------", | ||
| "playerB": "----------AAAAKKKKQQQQJJJJ" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 40, | ||
| "tricks": 4 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "1f8488d0-48d3-45ae-b819-59cedad0a5f4", | ||
| "description": "easy card combination, inverted decks", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "----------AAAAKKKKQQQQJJJJ", | ||
| "playerB": "--------------------------" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 40, | ||
| "tricks": 4 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "98878d35-623a-4d05-b81a-7bdc569eb88d", | ||
| "description": "mirrored decks", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "-A-A-K-K-Q-Q-J-J----------", | ||
| "playerB": "-A-A-K-K-Q-Q-J-J----------" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 59, | ||
| "tricks": 4 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "3e0ba597-ca10-484b-87a3-31a7df7d6da3", | ||
| "description": "opposite decks", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "-A-A-K-K-Q-Q-J-J----------", | ||
| "playerB": "----------J-J-Q-Q-K-K-A-A-" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 151, | ||
| "tricks": 21 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "92334ddb-aaa7-47fa-ab36-e928a8a6a67c", | ||
| "description": "random decks #1", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "K---J----AK---J-J---------", | ||
| "playerB": "--KAQ-A-Q-----Q-K--A-Q-J--" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 542, | ||
| "tricks": 76 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "30477523-9651-4860-84a3-e1ac461bb7fa", | ||
| "description": "random decks #2", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "-A---QJ-----KA--K---K---K-", | ||
| "playerB": "----QJA------JA-Q-JQ------" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 327, | ||
| "tricks": 42 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "20967de8-9e94-4e0e-9010-14bc1c157432", | ||
| "description": "Kleber 1999", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "---JQ---K-A----A-J-K---QK-", | ||
| "playerB": "-J-----------AJQA----K---Q" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 5790, | ||
| "tricks": 805 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "9f2fdfe8-27f3-4323-816d-6bce98a9c6f7", | ||
| "description": "Collins 2006", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "A-QK------Q----KA-----J---", | ||
| "playerB": "-JAK----A--Q----J---QJ--K-" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 6913, | ||
| "tricks": 960 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "c90b6f8d-7013-49f3-b5cb-14ea006cca1d", | ||
| "description": "Mann and Wu 2007", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "K-KK----K-A-----JAA--Q--J-", | ||
| "playerB": "---Q---Q-J-----J------AQ--" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 7157, | ||
| "tricks": 1007 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "a3f1fbc5-1d0b-499a-92a5-22932dfc6bc8", | ||
| "description": "Nessler 2012", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "----Q------A--K--A-A--QJK-", | ||
| "playerB": "-Q--J--J---QK---K----JA---" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 7207, | ||
| "tricks": 1015 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "9cefb1ba-e6d1-4ab7-9d8f-76d8e0976d5f", | ||
| "description": "Anderson 2013", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "--A-Q--J--J---Q--AJ-K---K-", | ||
| "playerB": "-J-------Q------A--A--QKK-" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 7225, | ||
| "tricks": 1016 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "d37c0318-5be6-48d0-ab72-a7aaaff86179", | ||
| "description": "Rucklidge 2014", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "-J------Q------AAA-----QQ-", | ||
| "playerB": "K----JA-----------KQ-K-JJK" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 7959, | ||
| "tricks": 1122 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "4305e479-ba87-432f-8a29-cd2bd75d2f05", | ||
| "description": "Nessler 2021", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "----K---A--Q-A--JJA------J", | ||
| "playerB": "-----KK---------A-JK-Q-Q-Q" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 7972, | ||
| "tricks": 1106 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "252f5cc3-b86d-4251-87ce-f920b7a6a559", | ||
| "description": "Nessler 2022", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "---AJ--Q---------QAKQJJ-QK", | ||
| "playerB": "-----A----KJ-K--------A---" | ||
| }, | ||
| "expected": { | ||
| "status": "finished", | ||
| "cards": 8344, | ||
| "tricks": 1164 | ||
| } | ||
| }, | ||
| { | ||
| "uuid": "b9efcfa4-842f-4542-8112-8389c714d958", | ||
| "description": "Casella 2024, first infinite game found", | ||
| "property": "simulateGame", | ||
| "input": { | ||
| "playerA": "---K---Q-KQAJ-----AAJ--J--", | ||
| "playerB": "----------Q----KQ-J-----KA" | ||
| }, | ||
| "expected": { | ||
| "status": "loop", | ||
| "cards": 474, | ||
| "tricks": 66 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
FraSanga marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| # Instructions | ||
|
|
||
| In this exercise, you will simulate the classic card game **Beggar-my-neighbour** (*Camicia*). | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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). | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Rules | ||
|
|
||
| * The deck is split between **two players**. Each player’s cards are represented as a string (top of the deck = leftmost character). | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * Players take turns placing the **top card** of their deck onto a central pile. | ||
|
|
||
| * If the card is a **number card** (`-` in this scenario), play simply passes to the other player. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * If the card is a **payment card**: | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * `J` → opponent must pay 1 card | ||
| * `Q` → opponent must pay 2 cards | ||
| * `K` → opponent must pay 3 cards | ||
| * `A` → opponent must pay 4 cards | ||
|
|
||
IsaacG marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * While paying, if the opponent reveals another payment card, the penalty immediately switches back. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * 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. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * The game ends when one player has no more cards. | ||
|
|
||
| ## Example | ||
|
|
||
| Here’s a simple example of input and output. | ||
|
|
||
| ```json | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "input": { | ||
| "playerA": "--------------------------", | ||
| "playerB": "----------AAAAKKKKQQQQJJJJ" | ||
| }, | ||
| "output": { | ||
| "status": "finished", | ||
| "cards": 40, | ||
| "tricks": 4 | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| ``` | ||
|
|
||
| ### Explanation: | ||
|
Check failure on line 43 in exercises/camicia/instructions.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * Player A only has number cards (`-`), so can never defend against a payment card. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Player B has a long sequence of Aces, Kings, Queens, and Jacks. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Each court card forces penalties, which Player A cannot counterattack, so Player B repeatedly wins the pile. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * 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). | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Your Task | ||
|
|
||
| * Parse the two players’ decks from the input. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * Simulate the game following the rules above. | ||
| * Return the result as an object with: | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| * `"status"`: `"finished"` or `"loop"` | ||
|
Check failure on line 56 in exercises/camicia/instructions.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * `"cards"`: total number of cards played throughout the game | ||
|
Check failure on line 57 in exercises/camicia/instructions.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * `"tricks"`: number of times the central pile was collected | ||
|
Check failure on line 58 in exercises/camicia/instructions.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Introduction | ||
|
|
||
| One rainy afternoon, you sit at the kitchen table playing cards with your grandmother.\ | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| The game is [Beggar-my-neighbour][bmn], or as she calls it, “Camicia.” | ||
|
Check failure on line 4 in exercises/camicia/introduction.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| At first it feels like just another friendly match:\ | ||
| cards slapped down, laughter across the table, the occasional victorious grin from Nonna.\ | ||
| 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. | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| You start to wonder:\ | ||
| _Will this game ever finish? Or could we keep playing forever?_ | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Later, driven by curiosity, you search online and to your surprise you discover that what happened wasn’t just bad luck.\ | ||
| You and your grandmother may have stumbled upon one of the longest possible sequences!\ | ||
| 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?_ | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| And so, armed with nothing but a deck of cards and some algorithmic ingenuity, you decide to investigate… | ||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| [bmn]: https://en.wikipedia.org/wiki/Beggar-my-neighbour | ||
|
Check failure on line 25 in exercises/camicia/introduction.md
|
||
FraSanga marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| title = "Camicia" | ||
| blurb = "Simulate the card game and determine whether the match ends or enters an infinite loop." | ||
| source = "Beggar-My-Neighbour" | ||
| source_url = "https://www.richardpmann.com/beggar-my-neighbour-records.html" |
Uh oh!
There was an error while loading. Please reload this page.