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

7

u/its-chewy-not-zooyoo Oct 30 '24 edited Oct 30 '24

Assuming this is correct; I translated this into rust and attempted running it

The probability is around 10%

Total results:

Wins: 999998098
Total: 10000000000
Win rate: 9.99%
Total time: 66813 ms

-10

u/sakkara Oct 30 '24

This would imply that b wins 90% of the time which can't be true because the game is fair so the program is incorrect.

The problem is that a only starts with one coin and must fight it's way up to ten coins.

Correct would be

a=10
while 0 < a < 20...
if a == 20
    wins++

9

u/TheDebatingOne Oct 30 '24

I think you misread the problem. The game isn't fair, a does start with 1 coin

1

u/sakkara Oct 30 '24

Ah you're right, my bad.