totalfloor = 10;
% Number of simulations to do for each case.
N = 1000000;
for skipfloor = 1:totalfloor-1
matchedN = 0;
for i = 1:N
[matched, a, b] = findfloor(totalfloor, skipfloor);
if matched == 1
matchedN = matchedN + 1;
end
end
p = 0;
for i = skipfloor+1:totalfloor
p = p + skipfloor/(i-1)*(1/totalfloor);
end
display(['number of floors to skip: ' num2str(skipfloor) ' number of simulations: ' num2str(n)]);
display(['number of cases in which biggest diamond is found:' num2str(matchedn) '. probability: ' num2str(matchedn/n)]);
display(['theoretical probability: ', num2str(p)]);
display([' ']);
end