# Nim

Acolyte
Posers and Puzzles 08 May '04 11:08
1. Acolyte
08 May '04 11:08
A version of the game Nim works as follows: You start with a collection of Skittles (the sweets), and players take it in turns to eat them, according to three rules:
1. You must eat at least one Skittle on your turn.
2. In any turn, all the Skittles you eat must be of the same colour.
3. If you eat the last Skittle, you lose.

Now suppose your opponent is feeling generous, and lets you decide who should go first. Assuming you want to win, how can you determine, given an arbitary collection of Skittles, whether it is better to go first or second?

This is a fairly well-known puzzle, so please don't shout out the answer if you know it already or have found it on the internet, try to work it out.
2. 08 May '04 22:58
Ithink you should go first but i am not sure
3. TheMaster37
Kupikupopo!
10 May '04 21:45
Without thinking too much i'd say it doesn't matter. Simply because you have to eat skittles of the same color.
4. Acolyte
11 May '04 12:45
Originally posted by TheMaster37
Without thinking too much i'd say it doesn't matter. Simply because you have to eat skittles of the same color.
Well, no. In each turn you have to eat skittles of the same colour, but in different turns you can eat different-coloured skittles. This game is ALWAYS a win either for player 1 or player 2 (assuming optimal play) based on the inital setup, because it's deterministic, complete-information, and has bounded duration, leaving no possibility of a draw at the end. The question is, given the initial setup of skittles, does the player who goes first win or lose?

For example: if all the skittles are the same colour, player 1 wins by eating all but one of them, if there's more than one skittle; if there's only one, player 1 loses because he has to eat the last one.
5. TheMaster37
Kupikupopo!
13 May '04 13:23
Hmm, then i have to think harder. i'll get back to this one ðŸ™‚
6. TheMaster37
Kupikupopo!
13 May '04 13:57
Ok, in the case that all piles have 3 or more skittles in them i have solved it:

1 pile: Player 1 wins by taking all but one
2 piles: Player 2 wins by making sure both piles are equal in size until he can leave one skittle. If player 1 can do so, he wins.
3 piles: Player 1 takes away one entire pile, or leaves one skittle of a pile, depending the number of skittles in the two piles left, according to the strategy with 2 piles.
4 piles: player 2 wins by keeping piles equal in size, two by two. Or loses if the number of skittles in each pile is equal in his turn (strategy of two piles)

And so on, making the difference between even and odd number of piles.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.redhotpawn.com/forum/posers-and-puzzles/nim.10547", "fetch_time": 1561024537000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2019-26/segments/1560627999200.89/warc/CC-MAIN-20190620085246-20190620111246-00257.warc.gz", "warc_record_offset": 873531384, "warc_record_length": 7163, "token_count": 720, "char_count": 2658, "score": 3.734375, "int_score": 4, "crawl": "CC-MAIN-2019-26", "snapshot_type": "latest", "language": "en", "language_score": 0.9555944204330444, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00009-of-00064.parquet"}