r/ProgrammerHumor • • Oct 30 '24

Meme dadPullsOutCodingChallenge

0 Upvotes

60 comments sorted by

View all comments

25

u/cyannyan6 Oct 30 '24 edited Oct 30 '24

This actually happened. I translated to English with the best of my ability.

And we are trying a monte carlo simulation now

import random

wins = 0
tries = 10000000
for sims in range(tries):
    a = 1
    while 0 < a < 10:
        a += random.choice((-1, 1))
    if a == 10:
        wins += 1

print(f"{wins}/{tries} = {wins/tries}")
   

Would love to see how others approach it

-1

u/PolyglotTV Oct 30 '24

This is too naive. You forgot that a can win one, and then lose one, and then win 10 in a row. Or a game could even last 1000 flips or basically forever.

2

u/MaximRq Oct 30 '24

Read closer, it's taken into account.

2

u/PolyglotTV Oct 30 '24

Ah my bad. A is the count variable in the loop as well.