You are using a version without Ads of this website. Please, consider donating:

basic probability question

bag has 16 balls
4 are red-12 white
if 2 balls are pulled -what is the prob. 1 is red?
not returning 1st ball or pulling both at same time
how can i calculate this?
1st ball 4/16 ; if white (12/16 it's white)
75% of time 1st is white and still have 4/15 chance to pull red
could someone please show me the formula for this
chances both red?
the bookie at the pub says it's 50%, I know it's lower
Thanks, IGGY
Last edited on
I got 9/20:
You have a 1/4 probability of getting red the first time.
And a 1/5 probability of getting red the second time. ((3/4)*(4/15))
 4 are red-10 white 1st ball 4/16 ; if white (12/16 it's white)

Whut?
The chance of both being red is about 1/20th.

For kicks:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768`` ``````#include #include #include #include enum Color { Red, NotRed } ; typedef std::vector bag ; bag createBag( unsigned redBalls, unsigned otherBalls ) { bag ballBag ; for (unsigned i=0; i(firstIsRed) / totalSamples ; float probBothAreRed = static_cast(bothAreRed) / totalSamples ; float probSecondIsRed = static_cast(secondIsRed) / totalSamples ; std::cout << "Probability first ball is red: " << probFirstIsRed * 100.0 << "%\n" ; std::cout << "Probability second ball is red: " << probSecondIsRed * 100.0 << "%\n" ; std::cout << "Probability both balls are red: " << probBothAreRed * 100.0 << "%\n" ; }`````` ```Probability first ball is red: 24.9147% Probability second ball is red: 24.9983% Probability both balls are red: 5.0139%```

 35 0 c:\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.6.1\include\c++\random In file included from c:\dev-cpp\mingw64\bin\../lib/gcc/x86_64-w64-mingw32/4.6.1/include/c++/random 3 C:\Dev-Cpp\Programs\000000.cpp from C:\Dev-Cpp\Programs\000000.cpp 32 2 c:\dev-cpp\mingw64\lib\gcc\x86_64-w64-mingw32\4.6.1\include\c++\bits\c++0x_warning.h [Error] #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options. C:\Dev-Cpp\Programs\000000.cpp In function 'bag createBag(unsigned int, unsigned int)': 14 17 C:\Dev-Cpp\Programs\000000.cpp [Error] 'bag' has no member named 'emplace_back' 17 17 C:\Dev-Cpp\Programs\000000.cpp [Error] 'bag' has no member named 'emplace_back' C:\Dev-Cpp\Programs\000000.cpp In function 'void randomize(bag&)': 24 12 C:\Dev-Cpp\Programs\000000.cpp [Error] 'mt19937' in namespace 'std' does not name a type 25 5 C:\Dev-Cpp\Programs\000000.cpp [Error] 'shuffle' is not a member of 'std' 25 50 C:\Dev-Cpp\Programs\000000.cpp [Error] 'engine' was not declared in this scope C:\Dev-Cpp\Programs\000000.cpp In function 'int main()': 39 10 C:\Dev-Cpp\Programs\000000.cpp [Error] 'ballBag' does not name a type 43 19 C:\Dev-Cpp\Programs\000000.cpp [Error] 'ballBag' was not declared in this scope

Compiler Errors for Code Above
 This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.

Enable C++11 support. And maybe update to a newer version of your compiler.
cire wrote:
Enable C++11 support. And maybe update to a newer version of your compiler.

I am using TDM-GCC 4.6.1, that's pretty new. I will see about C++11 support. Any IDE's that have it?
Last edited on
You enable it by using the compiler flags "-std=c++0x" or "-std=gnu++0x" when invoking the compiler (as indicated in the error message.) Generally, IDEs will have a menu for selecting/setting compiler flags per project. If the one you're looking for isn't present, they will also usually have an option where you can add the flag manually to the command line the IDE uses to invoke the compiler.
sorry- 4 red 12 white
cire: There's a bug in your sampling method. The probability of each of two items independently meeting a condition is not necessarily equal to the probability of either of the same two items meeting it.
For example, in the set {10,11,01}, bit 0 is 1 with P=2/3, and bit 1 is 1 with P=2/3, but (bit 0)|(bit 1) is 1 with P=1.

The value Script Coder arrived at is correct, but the reasoning he used is incorrect.
Probability of first ball not being red: 12/16
Probability of second ball not being red: 11/15
Probability of neither ball being red: (12/16)*(11/15)
Probability of either ball being red: 1-(12/16)*(11/15) = 9/20

Here's the fixed program:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071`` ``````#include #include #include #include #include enum Color { Red, NotRed } ; typedef std::vector bag ; void createBag(bag &ballBag, unsigned redBalls, unsigned otherBalls ){ for (unsigned i=0; i(firstIsRed) / totalSamples ; float probBothAreRed = static_cast(bothAreRed) / totalSamples ; float probSecondIsRed = static_cast(secondIsRed) / totalSamples ; float probEitherIsRed = static_cast(eitherIsRed) / totalSamples ; std::cout << "Probability first ball is red: " << probFirstIsRed * 100.0 << "%\n" ; std::cout << "Probability second ball is red: " << probSecondIsRed * 100.0 << "%\n" ; std::cout << "Probability both balls are red: " << probBothAreRed * 100.0 << "%\n" ; std::cout << "Probability of either ball being red: " << probEitherIsRed * 100.0 << "%\n" ; }``````
Last edited on
 if 2 balls are pulled -what is the prob. 1 is red? not returning 1st ball or pulling both at same time

Yes. Somehow I read that as "what is the probability the first ball is red," and given the inarticulate expression of the question, I guess it didn't bother me that it didn't make much sense, and advanced to the question that did make sense to me:

 could someone please show me the formula for this chances both red?