Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

  • Answers 119
  • Created
  • Last Reply

Top Posters For This Question

Recommended Posts

  • 0

import random

NUMBER_OF_BALLS = 4

NUMBER_DRAWN = 2

NUMBER_OF_BAGS = 100000

TOTAL_COLORS = 2

TEST_VALUE = '1'

def main():                                         #define main

    total_colors = TOTAL_COLORS

    number_of_bags = NUMBER_OF_BAGS

    number_of_balls = NUMBER_OF_BALLS

    number_drawn = NUMBER_DRAWN

    test_value = TEST_VALUE

    bags = []

    balls = []

    store_2 = 0

    store_3 = 0

    store_4 = 0

    while number_of_bags > 0:

        bag = []

        number_of_balls = NUMBER_OF_BALLS

        while number_of_balls > 0:

            ball_color = str(random.randint(1,total_colors))

            if ball_color == test_value:

                bag += test_value

            else:

                bag += "0"

            number_of_balls -= 1

        bags.append(bag)

        number_of_bags -= 1

    number_of_balls = NUMBER_OF_BALLS

    for elements in bags:

        ball = []

        for pulled in range(0,number_drawn):

            pulled_ball = str(random.randint(0,number_of_balls - pulled-1))

            ball += pulled_ball

        balls.append(ball)

    index_counter = len(bags)

    for index in range(0, index_counter):

        white_ball = 0

        total_left = 0

        for draws in range(0,((number_drawn))):

            if bags[index][(int(balls[index][draws]))] == test_value:

                white_ball += 1

            del bags[index][(int(balls[index][draws]))]

        if white_ball == number_drawn:

            for elements in bags[index]:

                total_left += int(elements)

            if total_left == (number_of_balls - number_drawn):

                store_4 += 1

            elif total_left == 1:

                store_3 += 1

            elif total_left == 0:

                store_2 += 1

    total_found = (store_2 + store_3 + store_4)*1.0

    print len(bags),"bags randomly filled with ",total_colors,"colors white/nonwhite"

    print "the number of times 2,3 or 4 white balls were present when the first two random drawn were white"

    print ' %5.7f' % (store_2/total_found*100),

    print " when only two balls where white"

    print ' %5.7f' % (store_3/total_found*100),

    print " when just three balls where white"

    print ' %5.7f' % (store_4/total_found*100),

    print " when all four balls where white"

    print "out of",int(total_found),"finds"

main()

this was the output

100000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

24.9277225 when only two balls where white

49.9839383 when just three balls where white

25.0883392 when all four balls where white

out of 24904 finds

-----------------------------------

100000 bags randomly filled with 10 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

79.8479087 when only two balls where white

19.1064639 when just three balls where white

1.0456274 when all four balls where white

out of 1052 finds

----------------------

Of course I could be wrong in my logic somewhere or my program isn't up to par or it or I am flawed but if you increase the amount of possible colors the odds of picking 2 white balls out of a bag of 4 white ball is slim because there hardly are all four white. I increase the number of iterations too and it seems to still be similar. I also increased it to 100 colors and once got no times was 2 white balls randomly drawn from an all 4 white bag. The only thing I could think about increasing was the iterations but my computer would be too slow and I didn't program it efficiently enough

---sorry it was written in Python ... it's the only one I have on my home computer but I'm sure you can make it happen on another platform

edit---spelling and clarification ... also I appologize for all the needless variables I was trying to make it so I could have any number of balls with any number of draws with any number of colors with any number of bags but I got lazy toward the end

Edited by PVRoot
Link to comment
Share on other sites

  • 0

import random

NUMBER_OF_BALLS = 4

NUMBER_DRAWN = 2

NUMBER_OF_BAGS = 100000

TOTAL_COLORS = 2

TEST_VALUE = '1'

def main():                                         #define main

    total_colors = TOTAL_COLORS

    number_of_bags = NUMBER_OF_BAGS

    number_of_balls = NUMBER_OF_BALLS

    number_drawn = NUMBER_DRAWN

    test_value = TEST_VALUE

    bags = []

    balls = []

    store_2 = 0

    store_3 = 0

    store_4 = 0

    while number_of_bags > 0:

        bag = []

        number_of_balls = NUMBER_OF_BALLS

        while number_of_balls > 0:

            ball_color = str(random.randint(1,total_colors))

            if ball_color == test_value:

                bag += test_value

            else:

                bag += "0"

            number_of_balls -= 1

        bags.append(bag)

        number_of_bags -= 1

    number_of_balls = NUMBER_OF_BALLS

    for elements in bags:

        ball = []

        for pulled in range(0,number_drawn):

            pulled_ball = str(random.randint(0,number_of_balls - pulled-1))

            ball += pulled_ball

        balls.append(ball)

    index_counter = len(bags)

    for index in range(0, index_counter):

        white_ball = 0

        total_left = 0

        for draws in range(0,((number_drawn))):

            if bags[index][(int(balls[index][draws]))] == test_value:

                white_ball += 1

            del bags[index][(int(balls[index][draws]))]

        if white_ball == number_drawn:

            for elements in bags[index]:

                total_left += int(elements)

            if total_left == (number_of_balls - number_drawn):

                store_4 += 1

            elif total_left == 1:

                store_3 += 1

            elif total_left == 0:

                store_2 += 1

    total_found = (store_2 + store_3 + store_4)*1.0

    print len(bags),"bags randomly filled with ",total_colors,"colors white/nonwhite"

    print "the number of times 2,3 or 4 white balls were present when the first two random drawn were white"

    print ' %5.7f' % (store_2/total_found*100),

    print " when only two balls where white"

    print ' %5.7f' % (store_3/total_found*100),

    print " when just three balls where white"

    print ' %5.7f' % (store_4/total_found*100),

    print " when all four balls where white"

    print "out of",int(total_found),"finds"

main()

this was the output

100000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

24.9277225 when only two balls where white

49.9839383 when just three balls where white

25.0883392 when all four balls where white

out of 24904 finds

-----------------------------------

100000 bags randomly filled with 10 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

79.8479087 when only two balls where white

19.1064639 when just three balls where white

1.0456274 when all four balls where white

out of 1052 finds

----------------------

Of course I could be wrong in my logic somewhere or my program isn't up to par or it or I am flawed but if you increase the amount of possible colors the odds of picking 2 white balls out of a bag of 4 white ball is slim because there hardly are all four white. I increase the number of iterations too and it seems to still be similar. I also increased it to 100 colors and once got no times was 2 white balls randomly drawn from an all 4 white bag. The only thing I could think about increasing was the iterations but my computer would be too slow and I didn't program it efficiently enough

---sorry it was written in Python ... it's the only one I have on my home computer but I'm sure you can make it happen on another platform

edit---spelling and clarification ... also I appologize for all the needless variables I was trying to make it so I could have any number of balls with any number of draws with any number of colors with any number of bags but I got lazy toward the end

3 things

(1) I <3 python

(2) it's only a sore subject in a tongue in cheek way

(3) your program shows that for N colors equally likely to be placed in the bag at the beginning, the chances of getting 2 more white balls is 1/N^2, which is what I would agree with. nice job on the coding

Link to comment
Share on other sites

  • 0

i remember this from a science class a while back.

imagine you have a pool of fish, but don't know how many there are. you want to count them in some way, without deceasing the population.

what you do is you catch fish, tag them, and then release them back into the water. when you start catching tagged fish, you can get a rough estimate of the population size of the pond;

total fish caught *untagged fish/ tagged fish aprox. = population.

then we went on to investigate, using coins, the optimum number of fish to catch. (when you tag the same fish three times is when you stop.)

perhaps we can use a similar approach here?

Link to comment
Share on other sites

  • 0

There are millions and millions of color combinations of which the rest two balls could be painted of.And white is just one color out of these millions of colors.And since 1 is very small compared to millions of million, my answer of the probability of the other two balls being white would be zero.

Link to comment
Share on other sites

  • 0

Ok, I agree. The sample space is not defined.

We are given there are 4 balls and 2 of these are white, but nothing about the color of the other balls. If we let the sample space be Q, i.e., the number of different colors a ball may be. Then our answer to the question would be:

1/[sigma(for n=1 to Q) n].

If the balls can only be white, this is 1/(1) = 1.

If the balls can be white and one other color, this is 1/(1+2) = 1/3.

If the balls can be white and any of two other colors, this is 1/(1+2+3) = 1/6.

And so forth.

Is the number of colors infinite? I will argue against this. I believe it is a phenominally huge number, but finite. Therefore, we have can not have the limit as Q approaches infinity which would permit an answer of 0 (zero). Thus, in conclusion, there is no specific number we can give for the probability.

Edited by Dej Mar
Link to comment
Share on other sites

  • 0

The probability of other two balls being white is same as the probability of any material particle having the speed of light.

What you say?

Edited by Harjot
Link to comment
Share on other sites

  • 0

there are two possible outcomes for each ball.

we already know that the first two are white and the remaining two can either be white (w) or non-white (n). therefore, there are 3 remaining possible outcomes (order doesn't matter) => {wn,nn,ww}. only the ww outcome satisfies "all balls being white" therefore the probability is 1/3.

That doesn't make probability of white and non-white equal.

Link to comment
Share on other sites

  • 0

if there are 4 white balls, the probability that the two chosen are white is 1

if there are 3 white balls, the probability that the two chosen are white is .5

if there are 2 white balls, the probability that the two chosen are white is .25

1+.5+.25=1.75

1/1.75=4/7

thus, the probability that all 4 balls are white is 4/7

Link to comment
Share on other sites

  • 0

A bag contains 4 balls.

Two balls are drawn at random and are found to be white.

What is the probability that all balls are white?

Phrases it "all balls are white"

0. I have a blue rubber ball in my bedroom.

Link to comment
Share on other sites

  • 0

import random

NUMBER_OF_BALLS = 4

NUMBER_DRAWN = 2

NUMBER_OF_BAGS = 1000000

TOTAL_COLORS = 2

TEST_VALUE = 1

def main():                                         #define main

    total_colors = TOTAL_COLORS

    number_of_bags = NUMBER_OF_BAGS

    number_of_balls = NUMBER_OF_BALLS

    number_of_draws = NUMBER_DRAWN

    test_value = TEST_VALUE

    bags = []

    balls = []

    bags_2 = [[1,1,0,0],[1,0,1,0],[1,0,0,1],[0,1,1,0],[0,1,0,1],[0,0,1,1]]

    bags_3 = [[1,1,1,0],[1,1,0,1],[1,0,1,1],[0,1,1,1]]

    bags_4 = [1,1,1,1]

    pulls  = [[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]

    store_2 = 0

    store_3 = 0

    store_4 = 0

    while number_of_bags > 0:

        bag = random.randint(2,4)

        if bag == 2:

            this_bag = random.randint(0,5)

            bags.append(bags_2[this_bag])

        elif bag == 3:

            this_bag = random.randint(0,3)

            bags.append(bags_3[this_bag])

        elif bag == 4:

            bags.append(bags_4)

        number_of_bags -= 1

    for elements in bags:

        ball = random.randint(0,5)

        balls.append(pulls[ball])

    index_counter_1 = len(bags)

    for index_1 in range(0,index_counter_1):

        white_ball = 0

        total_left = 0

        draws = len(balls[index_1])

        for draw in range(0,draws):

            index_2 = balls[index_1][draw]

            if bags[index_1][index_2] == test_value:

                white_ball += 1

        if white_ball == 2:

            for elements in bags[index_1]:

                total_left += elements

            if total_left == 4:

                store_4 += 1

            elif total_left == 3:

                store_3 += 1

            elif total_left == 2:

                store_2 += 1

    total_found = (store_2 + store_3 + store_4)*1.0

    print len(bags),"bags randomly filled with ",total_colors,"colors white/nonwhite"

    print "the number of times 2,3 or 4 white balls were present when the first two random drawn were white"

    print ' %5.7f' % (store_2/total_found*100),

    print " when only two balls where white"

    print ' %5.7f' % (store_3/total_found*100),

    print " when just three balls where white"

    print ' %5.7f' % (store_4/total_found*100),

    print " when all four balls where white"

    print "out of",int(total_found),"finds"

main()

The other assumption was that the possibilities of having 2 or 3 or 4 white balls had all the same weight ... therefore this output was

-------------------------------------

1,000,000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

9.9687935 when only two balls where white

30.0518788 when just three balls where white

59.9793277 when all four balls where white

out of 555,333 finds

--------------------------------------

10,000,000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

9.9983298 when only two balls where white

30.0156334 when just three balls where white

59.9860369 when all four balls where white

out of 5,556,058 finds

-----------------------

Therefore: It does depend on which assumption we make first. I'm pretty sure I have the combinations of bags and the combinations of pulled balls correct. I tried to make it as random as possible.

edit: I added the comma's and a couple spaces just for clarity

Link to comment
Share on other sites

  • 0

but now there are only two balls to be drawn so technically your only options are they are both white or they are not both white... therfore your "probabillity" (no real math) of them being both white is 50%

Link to comment
Share on other sites

  • 0

But ignoring all the statistics, (i know everyone is freaking out) technically you are only looking at the last two balls because you already know that the other two are white?

but now there are only two balls to be drawn so technically your only options are they are both white or they are not both white... therfore your "probabillity" (no real math) of them being both white is 50%

Link to comment
Share on other sites

  • 0

import random

NUMBER_OF_BALLS = 4

NUMBER_DRAWN = 2

NUMBER_OF_BAGS = 1000000

TOTAL_COLORS = 2

TEST_VALUE = 1

def main():                                         #define main

    total_colors = TOTAL_COLORS

    number_of_bags = NUMBER_OF_BAGS

    number_of_balls = NUMBER_OF_BALLS

    number_of_draws = NUMBER_DRAWN

    test_value = TEST_VALUE

    bags = []

    balls = []

    bags_2 = [[1,1,0,0],[1,0,1,0],[1,0,0,1],[0,1,1,0],[0,1,0,1],[0,0,1,1]]

    bags_3 = [[1,1,1,0],[1,1,0,1],[1,0,1,1],[0,1,1,1]]

    bags_4 = [1,1,1,1]

    pulls  = [[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]]

    store_2 = 0

    store_3 = 0

    store_4 = 0

    while number_of_bags > 0:

        bag = random.randint(2,4)

        if bag == 2:

            this_bag = random.randint(0,5)

            bags.append(bags_2[this_bag])

        elif bag == 3:

            this_bag = random.randint(0,3)

            bags.append(bags_3[this_bag])

        elif bag == 4:

            bags.append(bags_4)

        number_of_bags -= 1

    for elements in bags:

        ball = random.randint(0,5)

        balls.append(pulls[ball])

    index_counter_1 = len(bags)

    for index_1 in range(0,index_counter_1):

        white_ball = 0

        total_left = 0

        draws = len(balls[index_1])

        for draw in range(0,draws):

            index_2 = balls[index_1][draw]

            if bags[index_1][index_2] == test_value:

                white_ball += 1

        if white_ball == 2:

            for elements in bags[index_1]:

                total_left += elements

            if total_left == 4:

                store_4 += 1

            elif total_left == 3:

                store_3 += 1

            elif total_left == 2:

                store_2 += 1

    total_found = (store_2 + store_3 + store_4)*1.0

    print len(bags),"bags randomly filled with ",total_colors,"colors white/nonwhite"

    print "the number of times 2,3 or 4 white balls were present when the first two random drawn were white"

    print ' %5.7f' % (store_2/total_found*100),

    print " when only two balls where white"

    print ' %5.7f' % (store_3/total_found*100),

    print " when just three balls where white"

    print ' %5.7f' % (store_4/total_found*100),

    print " when all four balls where white"

    print "out of",int(total_found),"finds"

main()

The other assumption was that the possibilities of having 2 or 3 or 4 white balls had all the same weight ... therefore this output was

-------------------------------------

1,000,000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

9.9687935 when only two balls where white

30.0518788 when just three balls where white

59.9793277 when all four balls where white

out of 555,333 finds

--------------------------------------

10,000,000 bags randomly filled with 2 colors white/nonwhite

the number of times 2,3 or 4 white balls were present when the first two random drawn were white

9.9983298 when only two balls where white

30.0156334 when just three balls where white

59.9860369 when all four balls where white

out of 5,556,058 finds

-----------------------

Therefore: It does depend on which assumption we make first. I'm pretty sure I have the combinations of bags and the combinations of pulled balls correct. I tried to make it as random as possible.

edit: I added the comma's and a couple spaces just for clarity

I said these assumptions would give these probabilities a long time ago. Thank you for validating those claims.

You've come up with 0.6 which is what the original poster said was the correct answer. To get that, you had to assume that getting any number of balls was equally likely as getting any other number of balls (assuming 2 types). This is completely different than assuming that for any particular ball, any color is equally as likely as any other (which gives 1/N^2 for N colors and 0.25 for 2 colors).

To get 0.6, you can't just randomly pick colors and put balls in the bag. No, you have to randomly pick numbers of white balls, and put that many white balls (whatever random number you picked). I imagine someone taking a spinner (like wheel of fortune) with different numbers of white balls to put in the bag: spinning it and putting that number in, then filling the remaining spots with non-white balls. That's how to get 0.6. In that case, you are as likely to have 4 white balls as 3 or as 2.

To get 0.25 (assuming white probability = non-white, or 2 equally likely colors ), you would need to have tons of non-white and white balls randomly mixed together (with equal proportions: e.g. # black = # white or (#black + #green + #red) = #white or etc for whatever colors you want), close your eyes and just put 4 of them into a bag.

Which randomizing method is more plausible for this type of question?

It's certainly easier to close your eyes and randomly put balls of random color into the bag. If the proportions are not specified, it is reasonable to assume equal proportions.

For lengthy explanations on why these methods give these probabilities see previous posts. I'm sure I derived both cases multiple times.

The answer that it is 0 because any possible color could be in the bag and because there are an infinite number (color comes from wavelength of light, and so can be represented by a continuous variable, meaning that it is not a finite set (sorry Dej Mar) ), also has some merit : but that is more of an out of the box solution in my opinion.

Link to comment
Share on other sites

  • 0

but now there are only two balls to be drawn so technically your only options are they are both white or they are not both white... therfore your "probabillity" (no real math) of them being both white is 50%

This is the same fallacy that Arbelle wonderfully handled.

Just because there are 2 possibilities, doesn't mean that they are both equal.

Using your same logic RoyalBlue,

when you buy a lottery ticket, you can either win the lottery or lose it. Does this mean that every time you buy a lottery ticket you have a 50% chance of winning?

Do you know anyone who can say that for all the times they've bought lottery tickets, they've won 50% of the time?

No. There are 2 possibilities, but losing is much more probable than winning.

Link to comment
Share on other sites

  • 0

A bag contains 4 balls.

Two balls are drawn at random and are found to be white.

What is the probability that all balls are white?

ans wud be 1/4

two out of four balls are white...den dere are following cases for rets of the balls....wwoo(o stands for other color),wwwo,wwow,wwww,

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

×
×
  • Create New...