aspose file tools*
The moose likes Programming Diversions and the fly likes Probability Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Other » Programming Diversions
Bookmark "Probability Question" Watch "Probability Question" New topic
Author

Probability Question

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Ok, so it's been a number of years since I had a class in statistics and probability and, now that I've run into a question on it, I, of course, can't remember how to figure this out. If someone could give me a hand, I'd appreciate it.
Let's say I'm going to roll 3 dice. Out of the 3 dice, I'm looking for just one "success." For Die A, a success would be to roll a 1, 2, or 3. For dice B and C, a success would be to roll a 1 or 2. What is the probability that at least 1 of the three dice results in a success? And what would be the probability that at least 2 of the three dice results in a success?
Now, just to throw a wrinkle in things, let's add a fourth die. On that die, a success would be a 1, 2, 3, or 4. Rolling all 4 dice, what would be my probability of 1 success? And what would be the odds of two successes?
I know there was a formula for these types of problems and, for the life of me, I can't remember what it was.
Anyway, as I know there are a ton of math geeks roaming these halls so I thought I'd ask here. If you know, I'd appreciate a bit of help.
Thanks,
Corey


SCJP Tipline, etc.
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
For the first case I can help out. For at least 1 success, there must be no non-successes. Non-success must mean that all 3 dice are 4,5, or 6. There is a 50% chance of rolling a 4,5, or 6 on any particular die. So the chance that all 3 roll 4, 5, or 6 is 50% * 50% * 50%, or 1/8. Therefor, the chance of at least 1 success is (1 - 1/8), or 7/8.
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
[QB]Let's say I'm going to roll 3 dice. Out of the 3 dice, I'm looking for just one "success." For Die A, a success would be to roll a 1, 2, or 3. For dice B and C, a success would be to roll a 1 or 2. What is the probability that at least 1 of the three dice results in a success? And what would be the probability that at least 2 of the three dice results in a success?[/B]
Okay, off the top of my head, assuming 6-sided dice:
Probability of Dice 1: Success: 1/2, failure: 1/2.
Probability of Dice 2: Success: 1/3, failure: 2/3.
Probability of Dice 3: Success: 1/3, failure: 2/3.
Probability of at least one success means the probability of NOT having all three fail. This is the easier task, because it just means multiplying the failures:
Probability of all failing: 1/2 * 2/3 * 2/3 = 4/18 = 2/9.
Probability of at least one success: 1 - (2/9) = 7/9 = 78%.

To figure out two out of three takes more work. I'd probably have to resort to a truth table to figure that one out.
Joe
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Oops, didn't read it carefully enough. For die A, 50% chance of non-success, and for B and C they are 2/3 chance of non-success each. So make that 1/2 * 2/3 * 2/3 = 2/9 chance of failure = 7/9 chance of success.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Billy Bobbins:
For the first case I can help out. For at least 1 success, there must be no non-successes. Non-success must mean that all 3 dice are 4,5, or 6. There is a 50% chance of rolling a 4,5, or 6 on any particular die. So the chance that all 3 roll 4, 5, or 6 is 50% * 50% * 50%, or 1/8. Therefor, the chance of at least 1 success is (1 - 1/8), or 7/8.

But, in the first case, only 1 die fails on a 4, 5, or 6. The other 2 dice fail on 3, 4, 5, and 6. That means that the first die would fail 50% of the time while each of the other two would fail 66% of the time, right? Using the same formula, I would get this:
50% * 66% * 66% = 1/2 * 2/3 * 2/3 = 4/18 = 22.2%
Therefore, I would get at least one success 100% - 22.2% = 77.8% of the time.
Correct?
Now, if I add a fourth die that succeeds on a 1, 2, 3, or 4, I would have this:
33% * 50% * 66% * 66% = 1/3 * 1/2 * 2/3 * 2/3 = 4/54 = 7.4%
In such a case, I would get at least one success 100% - 7.4% = 92.6% of the time.
Okay, so that seems simple enough - I just multiply the individual probabilities together. But what about the second situation where I need more than just one success?
Billybob Marshall
Ranch Hand

Joined: Jan 27, 2004
Posts: 202
Originally posted by Corey McGlone:

But, in the first case, only 1 die fails on a 4, 5, or 6. The other 2 dice fail on 3, 4, 5, and 6. That means that the first die would fail 50% of the time while each of the other two would fail 66% of the time, right? Using the same formula, I would get this:
50% * 66% * 66% = 1/2 * 2/3 * 2/3 = 4/18 = 22.2%
Therefore, I would get at least one success 100% - 22.2% = 77.8% of the time.
Correct?

Right - see my subsequent post in which I corrected myself.

Now, if I add a fourth die that succeeds on a 1, 2, 3, or 4, I would have this:
33% * 50% * 66% * 66% = 1/3 * 1/2 * 2/3 * 2/3 = 4/54 = 7.4%
In such a case, I would get at least one success 100% - 7.4% = 92.6% of the time.
Okay, so that seems simple enough - I just multiply the individual probabilities together. But what about the second situation where I need more than just one success?

I'd have to think about it alot more like the other guy said. I could probably figure it out but don't want to spend that much time.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Well, I managed to determine the answers to my other questions, but I did it through some brute force. Basically, I made truth tables that look a lot like this. In this case, I have given the probability of each die failing (represented by an F) and succeeding (represented by an S). Then, I can multiply the 3 probabilities together to get the probability of such a roll and, in the end, I can add those probabilities to see what the odds of getting 2 successes or more. Note that Die 1 succeeds on a roll of 3 or less while dice 2 and 3 succeed on rolls of 2 or less.

Therefore, rolling 3 dice in which Die 1 has a 50% chance of succeeding and dice 2 and 3 have a 33% chance of succeeding, I have a 33.3% chance of getting 2 or more successes in one roll while I had over a 75% chance of getting at least one success.
I can do the same procedure to determine what the odds would be if I added a fourth die, that succeeded on a roll of 4 or less. In this case, Die one succeeds on a roll of 4 or less, 2 on a roll of 3 or less, and 3 and 4 on a roll of 2 or less.

So, it would appear that, by adding that extra die that succeeds at a 4 or less, I can raise the chances of 2 or more successes from 33.3% to 59.3%.
This works, but if the situations got any more complicated, it would easily become too cumbersome. I'm sure there's a formula for doing this, but heck if I can find it.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
So, it would appear that, by adding that extra die that succeeds at a 4 or less, I can raise the chances of 2 or more successes from 33.3% to 59.3%.
Here are my results, from Monte-Carlo simulation:
Rolling 4 dice:
Probability of at least one success : 0.9259764
Probability of at least two successes : 0.6297227
From multiple runs, the variation didn't exceed 0.0003, so I am questioning your 59.3%.

[ January 29, 2004: Message edited by: Eugene Kononov ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Tell you what, it will be easier to post code in Programming Diversions since there we've got HTML diabled (as for most other forums). That ends up making it easier to post code. So I'm moving this to Programming Diversions now...


"I'm not back." - Bill Harding, Twister
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Originally posted by Eugene Kononov:

From multiple runs, the variation didn't exceed 0.0003, so I am questioning your 59.3%.

You're right. After looking back at my table, I missed a possibility. This one:
Die 1: Success = 2/3
Die 2: Failure = 1/2
Die 3: Success = 1/3
Die 4: Success = 1/3
There is a 2/54 chance of this occurring, which equates to 3.7%. If you add 3.7% to my original 59.3%, you come up with 62.96%, which is right on the money with your experiment that resulted in 62.97%.
As you can see, even a simple problem like this becomes very complicated and things can be missed using this table approach. It is certainly not the most elegant solution.
Thanks for the experimentation, though. Very nicely done.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

hmmmm...
there are 1296 possible ways to roll 4 dice (assuming they are indeed 6-sided).
so, on half of these, die 1 will give a success. 648.
of the remaining 648 where die one fails, 1/3 would succeed with die 2. 216.
that leaves 432 possiblities where 1 and 2 fail. of these, 1/3 of them will give a success on die 3, or 144.
of the remaining 288 rols, die 4 would succedd 2/3 of the time, or 192 times.
so, 648+216+144+192 = 1200
1200/1296 = 92.59%
what i'd do for more than one success is write 4 nested loops that tests every possible outcome of the dice, similar to the test in Eugene's code. testing 1296 rolls should be faster than testing his million, and should give more accurate results.
[ January 29, 2004: Message edited by: fred rosenberger ]

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Hey Eugene - could you edit your post above to replace the image with code now? (Now that it presumably will work.) The image was a little too wide, forcing the whole page to be equally wide, which made the formatting look like crap if your browser window is too small. So I replaced the inline image with a link, but you'll probably prefer to put in text now. Plus it will be easier for people to copy & paste your code in their own editors. Thanks...
[ January 29, 2004: Message edited by: Jim Yingst ]
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
Based on the program Eugene wrote, I came up with this little prorgam:

This allows you to change the number of dice you want to roll arbitrarily and shows you the percentages of obtaining any number of successes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Probability Question