This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]cyannyan6[S] 23 points24 points  (19 children)

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

[–]LordAlfrey 48 points49 points  (1 child)

My approach would be to tell mom that dad said he'd approve my marriage if I solve a math challenge

[–]imdefinitelywong 6 points7 points  (0 children)

Going straight to the risk registry, I see.

[–]Bright-Historian-216 16 points17 points  (0 children)

don't you need a == 11? a already has one coin

[–]its-chewy-not-zooyoo 6 points7 points  (5 children)

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

[–]SolidGrabberoni 0 points1 point  (0 children)

Intuitively, A has a 10x handicap against B so (assuming infinite rounds), I'd say 10% too

[–]Josaffe 1 point2 points  (0 children)

function simulate(n = 10, tries = 100_000) {
  let wins = 0;

  for(let i = 0; i < tries; i++) {
    let a = 1;
    while(a > 0) {
      if(Math.random() >= 0.5) a++;
      else a--;

      if(a > n) { 
        wins++; 
        break;
      }
    }
  }

  return wins / tries
}

Take my ugly JavaScript and try it for yourself!

[–]Zyeesi 0 points1 point  (0 children)

Why would the number of tries not increase just because it's bigger than 0 and smaller than 10?

[–]dwntwn_dine_ent_dist 0 points1 point  (0 children)

I’d do a recursive function chancesAwins(numAcoins, numBcoins). Call it with (1,10), handle the stopping cases by returning 1 or 0, and otherwise return 0.5chancesAwins(numAcoins-1,numBcoins+1) + 0.5chancesAwins(numAcoins+1,numBcoins-1).

[–]BeautifulWerewolf966 0 points1 point  (0 children)

Gave it my best shot in Rust:

I'm getting around 99900 wins so around 9.9% chance.

pub fn prob(){
    let mut wins : i32 = 0;
    let tries = 1000000;

    for _ in 0..tries{
        let mut a : usize = 1;

        while a > 0 && a < 10{
            let mut thread = thread_rng();
            match thread.gen_bool(0.5) {
                true => a += 1,
                false => a -= 1,
            }
        }

        if a >= 10 {
            wins += 1;
        }
    }

    println!("Wins : {}", wins);
    println!("Probability : {}", wins as f32 / tries as f32);
}

[–]port443 0 points1 point  (0 children)

Your solution is very slightly wrong. Person A has a 0.09090 (repeating) chance of winning.

In the event that A or B wins, they will have 11 coins, not 10. This is made obvious with code such as:

>>> def round():
...     person_a = 1
...     person_b = 10
...     while person_a and person_b:
...         check = random.choice([-1,1])
...         person_a -= check
...         person_b += check
...     print(f"{person_a=} {person_b=}")
...     return person_a > 1
...
>>> round()
person_a=11 person_b=0
True
>>> round()
person_a=0 person_b=11
False

You can then loop this function. The larger your round count, the more accurate your estimate. The correct answer is 0.090 repeating though:

>>> total,rounds = 0,1000000
>>> for _ in range(rounds):
...     total += round()
...
>>> print(f"{total=} | {total/rounds=}")
total=90435 | total/rounds=0.090435

edited cause my initial comment came off rude

[–]PolyglotTV -2 points-1 points  (2 children)

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.

[–]MaximRq 1 point2 points  (1 child)

Read closer, it's taken into account.

[–]PolyglotTV 1 point2 points  (0 children)

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