Share your repls and programming experiences

← Back to all posts
You CAN'T beat this game. You just can't.
h
DynamicSquid (2025)

So there are 12 sticks. The last stick (left most one) is the special stick. If you can take that stick, then you win. But in order to take that stick, you and the computer must take turns starting from the right end and taking either 1, 2, or 3 sticks at a time.

For example, you can take 2 sticks, while the computer takes 1. And whoever ends up taking the last stick wins the game.

Easy... right?

Commentshotnewtop
Codemonkey51 (756)

I've watched a video on this stuff I forgot how it works but it is imposible (unless there are an odd amount of sticks or you go second)

Codemonkey51 (756)

Ye ik some not for profit organizations use a slightly different version of this gamer as a fundraiser (you pay to play) and unless you know the trick (game is unwinable if you go first and there is an even #). You will always lose and people will do it again and again to try to win. @DynamicSquid

StudentFires (327)

@Codemonkey51 I think I once saw VSause on this.

Codemonkey51 (756)

Ye I think that's how I know about it @StudentFires

AmazingMech2418 (658)

@Codemonkey51 What it is is that 12 is a multiple of 4 and, given an input from 1 to 3, another input can always get you to 4, so after an even number of attempts, it is possible to win the game (given that you are the second player of course!).

Codemonkey51 (756)

Yes that's what the video talked about and went into more detail:) @AmazingMech2418

AmazingMech2418 (658)

@Codemonkey51 Basically how this works:
1. You choose your number
2. CPU chooses - if 1, 3. if 2, 2. if 3, 1. - ends at 8
3. Repeat 1-2 - ends at 4
4. Repeat 1-2 - ends at 0 on CPU turn - CPU wins.

DannyIsCoding (489)

Make the game so the player is second and you win.
Also, nice program. I mainly code python, but i want to learn C++ too and so I learned some C++ :)

StudentFires (327)

Btw: for portability, don't use system("clear"), use std::wcout or wprintf on L"\e[H\e[2J", that's the shortest ANSI sequence for clearing the terminal.

DynamicSquid (2025)

@StudentFires So would it be something like std::wcout << L"\e[H\e[2J"?

StudentFires (327)

@DynamicSquid Yeah. If doesn't need to be wcout, especially since you weren't using it everywhere else like I do.
So more like:
std::cout << "\e[H\e[2J".

lolOOF (6)

eh theres a python version of this game in its turtle library

StudentFires (327)

If I recall correctly, it's just who starts first.