Share your repls and programming experiences

← Back to all posts
Yahtzee!!! 🎲🎲🎲🎲🎲

Yahtzee

# Hello hello hello!

#### So what is Yahtzee?

Yahtzee is a popular dice game where you have 5 dice (each dice having 6 sides, and the numbers 1 - 6 written on the sides. Just normal dice). The aim of the game is to roll those dice and to try to get at least 3 dice of the same value. The full game has a few more stuff, what I have done is a bit more simplified. Rolling all five dice with the same number (like all of them have the number 2) gets you the most points possible. That is called Yahtzee. (I think you’re supposed to shout that out loud if you get it xDD)

#### My version

So like I said earlier, what I did is a simplified version of the game. Mine is kinda a simulation.

• You will be able to either roll the dice manually (by pressing enter) or by doing it automatically for a number of times set by you (careful not to put a value too big or it’ll crash!).

• At the end of the simulations, you will be given a summary with how many rolls you did, how much times you got 3 Of A Kinds/4 Of A Kinds/Yahtzees, and your total points. In this version, I put 3 Of A Kinds at 6 pts, 4 Of A Kinds at 12 pts, and Yahtzees at 50 pts.

Ok, so first of all, I have my list containing 5 dice. I then rolled a random number from 1 to 6 for each of the 5 dice. remember that lists start at index 0.

Next, instead of using loads and loads of `if` statements to check if the numbers are the same, I just used the `sort()`. This sorts the dice from smallest to largest.

So for example, if I rolled `[5] [6] [5] [5] [1]`, the `sort()` will sort them like this: `[1] [5] [5] [5] [6]`. As you can see, I have a 3 Of A Kind.

Next, I use a bit of conditionals to determine if I scored anything. Like if I scored a Yahtzee, that would mean that all the dice are the same. So I can just do `if dice[0] == dice[4]:` which checks if the 1st dice equals the last dice. Since the dice are already arranged from smallest to largest, then it sees that I got a Yahtzee!

Lets go back to my 1st example.

These are my dice: `[1] [5] [5] [5] [6]` and they are sorted from smallest to largest. The first `if`statement checks if there is Yahtzee. Is the first index equal to the last one? No, so no Yahtzee.

Then, it checks if its a 4 Of A Kind like this:
`elif dice[0] == dice[3] or dice[1] == dice[4]:`
Again, that condition isn’t verified.

Last conditional, it checks if there is a 3 Of A Kind:
`elif dice[0] == dice[2] or dice[1] == dice[3] or dice[2] == dice[4]:`
Aha! So we can see that `dice[1] == dice[3]` which means that the dice at index 1 = the dice at the index 3. This means that I have scored a 3 Of A Kind!

(I hope that wasn’t too long/unnecessarily boring or complicated ;)

#### Chances of getting a Yahtzee

Planning on getting those 50 points? You’ll have to be very, very, very, very lucky. Lets do the math:

There are 5 dice, each with 6 sides. This means there are 6 x 6 x 6 x 6 x 6 = 6^5 = 7776 possible different combinations. A lot.

So if you want all the dice to have the same numbers; you have 6 possibilities (five 1s, five 2s, five 3s, etc.).

Next, we divide the number of possible Yahtzees (6) by the total possible rolls (7776), you get 6/7776 = 1/1296.

Yep, the odds of getting a Yahtzee is 1 chance over 1296. That’s about 0.08 percent.

#### Some gameplay

As you can see, I’ve rolled 10 times, and only gotten one 3 Of A Kind, no Yahtzee (duh).

I roll 100 times, and I’ve gotten six 4 Of A Kinds and nineteen 3 Of A Kinds, still no Yahtzee.

I roll 1000 times, twenty-two 4 Of A Kinds and one hundred and eighty eight 3 Of A Kinds, and still no Yahtzees again.

But now I rolled 10000 times, and I’ve finally gotten 4 Yahtzees with almost two hundred 4 Of A Kinds and almost two thousand 3 Of A Kinds.

Well, that’s all I think. Try this out and tell me what you think. I find it mind boggling how many possibilities there are in only 5 dice, and how hard it is to get a Yahtzee.

So if y’all every play the actual game, just know that you’ll have to throw dice a few thousand times to get some Yahtzees!

# Everyone have an amazing day! =)

PS: Fun Fact Because Why Not!

`Goodbye`comes `from Godbwye` which is a contraction of the phrase `God Be With Ye`. So yea good bye!

(Source: I think I read it in the NYT but here is where I looked it up from: https://www.todayifoundout.com/index.php/2012/01/where-the-term-goodbye-comes-from/#:~:text=%E2%80%9CGoodbye%E2%80%9D%20comes%20from%20the%20term,Gabriel%20Harvey%20wrote%20in%201573.)

[deleted]

Omg i so lucki :oooo

firefish (877)

@behavingEffort Wow your die must be biased

firefish (877)

k9chelsea2 (731)

:OOOOO how did you dewit @behavingEffort ?????

codeitfast (47)

@behavingEffort There must be a HUGE bug XD.

[deleted]

@k9chelsea2 lucky!!!!!

Jakman (462)

Jakman (462)

@JosephSanthosh he's growing. It might have been a slower start than usual but he is growing. I can tell

JosephSanthosh (1188)

@Jakman I'm growing too ... sideways btw.

Jakman (462)

@JosephSanthosh you should get that checked out. Sounds like a bad case of diabetes

JosephSanthosh (1188)

Haha! i'm like 110 pounds, that's why u shud never be a runner for cross country or track n field. @Jakman

Jakman (462)

@JosephSanthosh my advice for you is to not go to prison anytime soon. You are very small.

Alice688 (97)

I LOVE this game. Also, please check out my account and maybe follow me. UwU

HEROBRATT (1)

I rolled 800 times and got 2 Yahtzees. Is that lucky?

Brooks2009 (2)

You rolled: 1 times

You got:
[0] Yahtzees (0 points)
[0] 4 Of A Kinds (0 points)
[1] 3 Of A Kinds (6 points)

Total points: 6

LUCKY!!!

HEROBRATT (1)

Lmao 🤣🤣🤣🤣🤣🤣🤣🤣

python88 (282)

out of 10 i got 1 four of a kind ond 3 3of a kinds

python88 (282)

out of 10000 i got 9 yatzees

EshaanAhuja (1)

I ate rolled 100 times and on The 72 time i got a yatgese

EshaanAhuja (1)

I got a Yahtzee on my 108 try

VivaanSa (29)

have you joined the language jam? (https://repl.it/jam)

TinaChen4 (12)

I rolled 600 times to get 1 yahtzee is that lucky or unlucky?

python88 (282)

i got 80 yahtzees!

python88 (282)

i used automatic for 9999999999999999 times and...

DigitCommander (31)

rolling 100000 times...

JSDRAGONCODER (7)

This pretty cool! And i noticed if automatic and press random very very high number, it sort of like animation

Bookie0 (4977)

wow lol thats a lot! ;) @DSAEvan

Name12 (155)

to be honest, this is quite a simple code. but in compartment to your other posts, it's better. good job!

[deleted]

So good! I really like this game. Good Job!

codeitfast (47)

I rolled it 10 million times and got 466 yahtzees!

codeitfast (47)

Nice! fyi, When you ask how many times to roll the dice, you asked how much times you should do it. The correct grammar for counting is "many".

Bookie0 (4977)

ah ok, thanks for telling me ;) @codeitfast

codeitfast (47)

@Bookie0 You're welcome. It doesn't really matter, tho

k9chelsea2 (731)

that was on the automatic roll thing and the number i did was one thousand

k9chelsea2 (731)

i also inputted a massive number like 382473047028438- but after about an hour the program (or browser prolly teh latter) crashed

ChezTacoz (343)

This game is 100% rigged

SixBeeps (3484)

I find it mind boggling how many possibilities there are in only 5 dice, and how hard it is to get a Yahtzee.

So I did the math and the answer kinda angers me. There are 6 faces on a die, and there are 5 dice, so the answer is 6^5

Which is 7776

Which is soooo close to 7777, but isn't.

Good work on this btw.

Bookie0 (4977)

Lmao yea so close 7777

Thanks :)

firefish (877)

Just casually holding down my enter key for five minutes on normal mode

firefish (877)

@Bookie0 They were scrolling by really fast, had to stop and scroll up when I saw something green. Which probably wasn't the first one I got

aguy11 (127)

The formula for luckier rolls with d as the number you wanted to roll: `l = d - 1`.
Proof:

-- YAHTZEE BATTLE --
10000 vs. 9999
Result for 9999:

13982 is bigger than 13964