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 with new interpretation | Comment 6 of 9 |
Apparently what's intended is that there are 10 rounds. At the end of each round 20 candies are eaten. In each round the first phase consists of one dispense in which the non-blues are rejected and sent back to the hourglass, and the second phase is another dispense, where whatever is presented into the cup is accepted.

A couple of sets of ten rounds is shown:

   first dispense           cup after rejects sent back   cup contents that are eaten  blues eaten
 
rrwwbgybbgrgwrgybywg          bbbb                          bbbbwrbrwyrybbrgwygr            7 
wwwwwbwrrrwgwywgygrr          b                             byybgygywgbbbbwrbgyb            8 
ywyyrrgywwwggygwrgyy                                        wwbgywyrbrywybybwggw            4 
bggbgwgwgyrwrrgwybrb          bbbb                          bbbbywrrryyrrbrgwgbr            6 
rgbyrgbwbbwywrygbwyb          bbbbbb                        bbbbbbrggwwrwygyrrgy            6 
gyygwyrywwgwwwywrrwg                                        rbbgrygwygywwbgrrywr            3 
ryybywggrgggwwbrwwrr          bb                            bbwwwywyywyrbgryywyg            3 
byggywwyggrrgrwwyyrw          b                             brgbrgyggrrwwyywwyrg            2 
gwywwrrwryyggygrwygw                                        ggggyrgwggyrygywgrwr            0 
rbrrywywwgggwwrwgwgr                  
     1  blues eaten in last cup

In the final round, there are only 20 left in the hourglass, so ultimately they are eaten. In this first case, there's only one blue candy in this last cup eaten. 
 
Second example:

gyyyrgbwywywwygwwgrg          b                             bgrbygrryyrrbbggwrby            5 
yyygbwrrwggwrbgyrgrw          bb                            bbywbgyyyywbgyrwrwgy            4 
grgywbgyggrrygwybryy          bb                            bbwbrrggwwwyyrwrrwyb            4 
gbgyrwgbrgggyybgygwy          bbb                           bbbgyygyybrbrwywyryg            5 
ybwwrywrbgrbwbyygwyg          bbbb                          bbbbryggrbyrwygwrrry            5 
grrggbbrbyygwywrbwyw          bbbb                          bbbbbbgrrwggwbgwrggg            7 
grbgwggrwgyrwwyrwyww          b                             byrrgrwwrywwbgyybggw            3 
gwrggywywgwrrwybwgrb          bb                            bbgrwwyyywwwrbywgbrw            4 
wgrryrbyyggygwbrwgbw          bbb                           bbbyggywgywrrrrgrgrg            3 
wwwgwwgwygrrygygwygw          
     0 blues eaten in last cup
     
In this second example, all the blue candies were eaten in rounds prior to the last round, so no blue candies were in the last cup.          
     
totct=0;counts=zeros(1,21);
for i=1:1000000
  cup='';
  hourglass0=[repmat('r',1,40) ...
    repmat('w',1,40) repmat('b',1,40) ...
    repmat('y',1,40) repmat('g',1,40) ];
  hourglass=hourglass0(randperm(200));
  % disp(hourglass)
  while ~isempty(hourglass)
    % disp(' ')
    if length(hourglass)<=20
      ct=sum((hourglass=='b'));
      cup=hourglass;
      % fprintf('%-30s\n',cup)
      hourglass='';
      continue
    else
      cup=hourglass(end-19:end);
      % fprintf('%-30s',cup)
      hourglass=hourglass(1:end-20);
    end

    hourglass=[hourglass cup(find(cup~='b'))];
    cup(find(cup~='b'))='';
    % fprintf('%-30s',cup)
    refill=20-length(cup);
    r=randperm(length(hourglass));
    hourglass=hourglass(r);

    if length(hourglass)<=refill
      cup=[cup hourglass];
      ct=sum((cup=='b'));
      % fprintf('%-30s\n',cup)
      hourglass='';
    else
      cup=[cup hourglass(end-(refill-1):end)];
      % fprintf('%-30s',cup)
      % fprintf('  %d' , sum(cup=='b'))
      hourglass=hourglass(1:end-refill);
    end

  end
  % disp(ct)
  totct=totct+ct;
  counts(ct+1)=counts(ct+1)+1;
end
fprintf('%9d/%d %10.8f\n',totct, i, totct/i)

The sample printing was commented out, to provide statistics for a million trials.

The results was

>> candies200
   486532/1000000 0.48653200
   
probably good to 3 places, 0.487

  Posted by Charlie on 2023-12-13 07:46:47
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 (9)
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