Saul, Simon and Stuart each have a bag containing 5 different colored marbles. Each bag contains the same five colors.
o Saul reaches into Simon's bag and Stuart's bag and randomly withdraws a marble from each and places them in his bag.
o Simon then reaches into Saul's and Stuart's bag and randomly withdraws a marble from each and places them in his bag.
o Finally, Stuart reaches into Saul's and Simon's bag and randomly chooses a marble from each and places them in his bag.
Determine the probability that each of the three boys has five different colors of marbles in their bag.
There are 5 ways Saul could make each of his two choices (choices 1 and 2).
There are 7 ways Simon could make his choice of one of Saul's marbles, and 4 ways of choosing among Stuart's remaining 4 marbles. These are choices 3 and 4.
And each of Stuart's choices is from each of the others' six remaining marbles.
The program lays out the sequences of choices in a list, before all the ways start being made. The list is 25200 rows of six choices each, chosen from the appropriate number of choices at each stage.
Each set is refreshed at the start with colors 1, 2, 3, 4 and 5 in each of the person's bags, and then the choices carried out.
This method avoids 6-deep nested loops during the playout, with only a 2-deep nesting to set up the sequences.
clearvars
choices=[5 5 7 4 6 6];
list=[];
for i=1:choices(1)
list=[list; i];
end
for chPos=2:6
list(:,chPos)=1;
hold=list;
for i=2:choices(chPos)
hold(:,chPos)=i;
list=[list; hold];
end
end
tot=0; succ=0;
for row=1:length(list)
saul=[1 2 3 4 5];
simon=[1 2 3 4 5];
stuart=[1 2 3 4 5];
takes=list(row,:);
saul(end+1)=simon(takes(1)); simon(takes(1))=[];
saul(end+1)=stuart(takes(2)); stuart(takes(2))=[];
simon(end+1)=saul(takes(3)); saul(takes(3))=[];
simon(end+1)=stuart(takes(4)); stuart(takes(4))=[];
stuart(end+1)=saul(takes(5)); saul(takes(5))=[];
stuart(end+1)=simon(takes(6)); simon(takes(6))=[];
tot=tot+1;
if isequal(sort(saul),[1 2 3 4 5]) ...
&& isequal(sort(simon),[1 2 3 4 5]) ...
&& isequal(sort(stuart),[1 2 3 4 5])
succ=succ+1;
end
end
fprintf('%7d %7d %15.13f %15.13f \n',succ, tot, succ/tot, tot/succ)
disp(sym(succ)/sym(tot))
finds
1040 25200 0.0412698412698 24.2307692307692
13/315
That is, 1040 successes out of the total of 25200 equally possible ways it could take place, for a probability of approximately 0.0412698412698 or 1 / 24.2307692307692. The exact probability is 13/315, the reduced form of 1040/25200.
I simulation with random choices is a good check.
Simulation with random choices agrees:
tot=0; succ=0;
for i=1:200000
saul=[1 2 3 4 5];
simon=[1 2 3 4 5];
stuart=[1 2 3 4 5];
takes=randi(length(simon));
saul(end+1)=simon(takes); simon(takes)=[];
takes=randi(length(stuart));
saul(end+1)=stuart(takes); stuart(takes)=[];
takes=randi(length(saul));
simon(end+1)=saul(takes); saul(takes)=[];
takes=randi(length(stuart));
simon(end+1)=stuart(takes); stuart(takes)=[];
takes=randi(length(saul));
stuart(end+1)=saul(takes); saul(takes)=[];
takes=randi(length(simon));
stuart(end+1)=simon(takes); simon(takes)=[];
tot=tot+1;
if isequal(sort(saul),[1 2 3 4 5]) ...
&& isequal(sort(simon),[1 2 3 4 5]) ...
&& isequal(sort(stuart),[1 2 3 4 5])
succ=succ+1;
end
end
fprintf('%7d %7d %15.13f %15.13f \n',succ, tot, succ/tot, tot/succ)
disp(sym(succ)/sym(tot))
8244 200000 0.0412200000000 24.2600679281902
2061/50000
|
Posted by Charlie
on 2022-05-07 13:24:06 |