All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > General
200 Candies (Posted on 2023-12-12) Difficulty: 3 of 5
I have 200 candies in an hourglass dispenser. There are 40 each of red, white, blue, yellow and green. Each time I turn the hourglass over the candies get thoroughly mixed and 20 candies are poured into a cup. I like the blue candies best.

When I want candy, I turn over the dispenser and sort through the candies in the cup. I leave all of the blue ones in the cup and put the rest back. Then I turn over the hourglass a second time. The dispenser fills the cup so that I get exactly 20 candies, which I eat. I continue this way until the dispenser is empty.

How many blue candies will be in the final cupful?

Note:The dispenser dispense just the right amount so that to total will still be 20; so if 4 blues remain, it will dispense 16.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Simulation | Comment 1 of 9
This is a simulation, not an exact calculation

Counting the number of blue candies per each of the 20 batches, after 10,000 trials:
[6.9392, 6.3839, 5.785, 5.2228, 4.5325, 3.8313, 3.0977, 2.2976, 1.4219, 0.4881]
So that the requested final cupful has an expected number of slightly less than 1/2 blue candy.

-------------
import random
candies = list('R'*40 + 'W'*40 + 'Y'*40 + 'B'*40 + 'G'*40)
random.shuffle(candies)
blue_list = [0 for n in range(10)]

big = 10000

for reps in range(big):
    random.shuffle(candies)
    remains = candies
    for n in range(10):
        random.shuffle(remains)
        if n < 9:
            dispensed = remains[:20]
            remains = remains[20:]
            tobereturned = []
            for d in dispensed:
                if d != 'B':
                    tobereturned.append(d)
            returnee_number = len(tobereturned)
            dispensed = ['B']*(20 - returnee_number)
            remains = remains + tobereturned
            random.shuffle(remains)
            dispensed = dispensed + remains[:returnee_number]
            remains = remains[returnee_number:]
            blue_list[n] += dispensed.count('B')
        else:
            dispensed = remains
            blue_list[n] += dispensed.count('B')


blues_per_batch = []
for b in blue_list:
    blues_per_batch.append(b/big)
print(blues_per_batch)   

  Posted by Larry on 2023-12-12 14:14:14
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information