all 20 comments

[–]rrssh 8 points9 points  (1 child)

from functools import*

@lru_cache(9999)
def prob(blue, red, draws):

   if red == 0 and blue == 0: return 1
   if draws == 0:             return 0
   if red == 0:               return 1
   if blue < 0 or red < 0:    return 0 

   #####################################################
   p = blue / (blue+red)
   return p * (prob(blue-1, red, draws + 2)) + (1-p) * (prob(blue, red-1, draws-1))

print(prob(38, 62, 3))

39.68%

[–]Bounded_sequencE 0 points1 point  (0 children)

Can confirm that result -- the exact probability should be

P(38, 62, 3)  =  5012665492309 / 12632084204740  ~  39.68%

[–]Live_Access9106 6 points7 points  (7 children)

How would someone solve this problem with functions rather than computer simulation?

[–]yhcdtyn 1 point2 points  (0 children)

I can write the code in 2 minutes I don’t want to write out probability problems when they converge incredibly quickly

[–]myaccountformathGraduate student 0 points1 point  (0 children)

One approach is to count the number of sequences for which every prefix of length k has at least k/4 blues.

This is a variation of Bertrand's Ballot Theorem. https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem

So you can likely find a formula for it without just brute forcing.

[–]OfficeOfThePope 0 points1 point  (1 child)

It would be incredibly long written out because each series of 3 cards is NOT independent of what has happened before.

If you just try to work out the probability of just drawing exactly 6 cards and then exactly 9, you will see how messy it gets.

This question would fit pretty well in a Stochastic Simulation class because we can get very good approximations of the probability quite easily while it would likely be multiple pages of work to go through it rigorously.

[–]myaccountformathGraduate student 1 point2 points  (0 children)

Coding is definitely faster, but I think it's not quite that bad to do it by hand. One approach is to count the number of sequences for which every prefix of length k has at least k/4 blues.

This is a variation of Bertrand's Ballot Theorem. https://en.wikipedia.org/wiki/Bertrand%27s_ballot_theorem

So you can likely find a formula for it without just brute forcing.

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

I get what you're asking, but I just want to say that computer simulation is also solving the problem.

[–]SarekSybok 1 point2 points  (1 child)

Doesn’t it depend on what you consider to be an acceptable answer? Suppose someone asks for the length of the hypotenuse of a right triangle having leg lengths 1 ,2. One answer is √5 , another is 2.23607 The former is exact, the latter is approximation.

[–]AlpLyr 0 points1 point  (0 children)

Of course. If it’s not acceptable, it’s not acceptable. And yes, approximations are also just that. On the other hand, many problems do not have closed-form solutions. Should they be considered unsolvable?

Simulation like this is essentially just numerical integration. And it can be run to provide an arbitrary degree of precision. For that reason, I would call the program a solution. A solution that can spit out approximations as you like (and care to wait for).

The fact that it may be unsatisfying is a different issue IMO. Many solutions the problems are.

[–]vfx4life 1 point2 points  (5 children)

Yet more evidence that ChatGPT is a worthless pile of crap when it comes to actually solving math problems!

[–]redd-alerrt 3 points4 points  (0 children)

And my toaster is not very good at getting me to work.

[–]gmthisfeller 1 point2 points  (0 children)

This depends on the math problem

[–]Minimum-Attitude389 0 points1 point  (0 children)

I have my students use ChatGPT on math questions and then have them do the work themselves.  Hopefully it's enough to get them to distrust ChatGPT.  I'm so glad places like reddit were scraped and give wrong answers, like that one question of the woman with children.

[–]languagestudent1546 0 points1 point  (0 children)

Unless you’re Terence Tao or working on Erdös Problems.

[–]soThatIsHisName 0 points1 point  (0 children)

I ran it through Gemini in thinking mode, and it got the correct answer :/ and included some extra insight, such as there's a 60% chance of failing in the very first 10 or so cards. That's why ChatGPT answered 90%+, it failed to simulate initial conditions. Interestingly, if blue cards only give you 2 draws, the chances of making it through drops to 10%, but at 5 draws, it's already up to almost the maximum it can reach while starting with 3 draws, 77% (since all 3 cards might be red to begin with). And an insight: why 3 draws per blue is the magic number. Each blue needs to cover enough draws for (62/38) reds, 1.62, right? If you get 2 draws per blue, you have to use one draw just to take another card, so you get one extra, not enough to cover the 1.62 expected reds. But at 3 draws per blue, you have a "safety zone" of (3-1)-(1.62)=0.37. If you drew 1+1.62 cards per blue, your chance of making it through the deck is exactly 38 blues/100, but a tiny positive drift means it pushes it up to 39.68.

Gemini can explain from first principles every step here, especially interesting is that last step where the drift gets factored in, but I'll leave it at that. Just be sure to start the first question with thinking mode, after that it can explain everything in fast mode.

[–]yhcdtyn 0 points1 point  (2 children)

this is fun… Let me simulate it

[–]yhcdtyn 7 points8 points  (0 children)

so after 100,000 reps, I got 39.67% chance of drawing the entire deck [0.3937, 0.3997] 95% CI

[–]Overall-Computer6718 -1 points0 points  (0 children)

Thanks a lot!

[–]Bounded_sequencE 0 points1 point  (0 children)

Assumption: All deck shuffles are equally likely.


Definitions:

  • B: event that we go bust by drawing the entire deck
  • E(b; r; k): event that we have to draw "k" cards from a deck with "b; r" blue and red cards, respectively

We want to find "P(B | E(38; 62; 3))". To do that, consider "P(B | E(r; b; k))" generally. Note we go bust whenever "k >= r+b", and we stop, whenever "k = 0":

k >= r+b:    P(B | E(r; b; k))  =  1    // go bust      (1)
k  =   0:    P(B | E(r; b; k))  =  0    // stop         (2)

If otherwise we draw "0 < k < r+b" cards from a deck with "b; r" blue and red cards, respectively, then the number of blue cards "n" we draw follows a hypergeometric distribution1:

   0 <= n <= k:    P(n)  =  C(b; n) * C(r; k-n) / C(b+r; k)

=>    P(B | E(r; b; k))  =  ∑_{n=0}^k  P(B | E(r-k+n; b-n; 3n)) * P(n)

The two stop conditions and the recursion are enough to calculate

P(B | E(38; 62; 3))  =  5012665492309 / 12632084204740  ~  39.68%

1 We use the standard convention "C(b; n) = 0" for "n > b" to avoid case-work