Share your repls and programming experiences

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

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?

Codemonkey51 (1061)

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 (1061)

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

xxpertHacker (931)

@Codemonkey51 I think I once saw VSause on this.

Codemonkey51 (1061)

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

AmazingMech2418 (1102)

@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 (1061)

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

AmazingMech2418 (1102)

@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.

CodingGoose (698)

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++ :)

xxpertHacker (931)

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 (5016)

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

xxpertHacker (931)

@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 (7)

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

xxpertHacker (931)

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