function p_est=MCASQ9f(darts)
% format p_est=MCASQ9f(darts)
% p_est is the estimated probability, darts number of darts
% MCAS Question 9
% Solves question 9, 10th grade math, 2001 MCAS
% Written by E Gallagher 9/5/01
% Eugene.Gallagher@umb.edu
% Last revised 9/6/01
clf % clears the previous graph
hold on; % no graphs will be erased;
theta = 0:pi/50:2*pi;
% first draw a circle of radius 3, centered at 0
r=3;
x = r * cos(theta) + 0;
y = r * sin(theta) + 0;
plot(x, y);axis('square');
% Now draw a circle of radius 1, centered at 0
r=1;
x = r * cos(theta) + 0;
y = r * sin(theta) + 0;
plot(x, y);
% Now fill this circle with yellow;
h =fill(x,y,'y');
hold on
figure(gcf)
% Modify dart throwing code from Nahin's pisim.m
% Vectorized
rand('state',100*sum(clock))  %set new seed for generator;
tic
X=rand(darts,2)*6-3;
r=sqrt(sum((X.^2)'));
i=find(r<3);
trials=length(i);
success=length(find(r(i)<1));
% set marker size
if darts>=1e6
    ms=0.5;
elseif darts>=1e5
    ms=1;
elseif darts>=1e4
    ms=2;
elseif darts>=1e3
    ms=3;
else
    ms=4;
end
plot(X(i,1),X(i,2),'.r','MarkerSize',ms);figure(gcf)
p_est=success/trials;
format long 
t=toc;
fprintf('The program took %5.4e seconds to analyze the distribution of %d darts.\n',t,darts);