\documentclass[twocolumn]{article}

\setlength{\oddsidemargin}{-0.5in}
\setlength{\evensidemargin}{-0.5in}
\setlength{\topmargin}{0.0in}
\setlength{\headheight}{0in}
\setlength{\headsep}{0in}
\setlength{\textwidth}{7.0in}
\setlength{\textheight}{9.5in}
\setlength{\parindent}{0in}
\setlength{\parskip}{0.05in}
\setlength{\columnseprule}{0.3pt}

\setlength\columnsep{25pt}

\usepackage{fancyvrb}
\usepackage{relsize}
\usepackage{hyperref}

\usepackage{listings}
\usepackage{amsmath}

\begin{document}

\lstset{xleftmargin=5mm,framexleftmargin=10mm,basicstyle=\footnotesize}

Name: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_

Directions: {\bf \Large Work only on this sheet} (on both sides, if
needed).  MAKE SURE TO COPY YOUR ANSWERS TO A SEPARATE SHEET FOR SENDING
ME AN ELECTRONIC COPY LATER.

{\bf Important note:}  Remember that in problems calling for R code, you
are allowed to use any built-in R function, e.g. {\bf choose()}, {\bf
sum()}, etc.  

{\bf 1.} This problem deals with the ALOHA simulation example on p.23.

\begin{itemize}

\item [(a)] (20) What variable in the program is analogous with the number of lines
in our ``notebook'' view?

\item [(b)](20) Suppose we want to add code to find P(collision during epoch
2).  We'll set a variable {\bf ce2} to 0 early in the code, and near the
end, we'll divide it by {\bf nreps}.  We'll need to add one more line of
code.  State the line number after which the new line is to be inserted,
and state what code goes there.  Sample answer:

\begin{lstlisting}
after line 10 insert "if (x == 0) y <- 3"
\end{lstlisting}

\end{itemize}

{\bf 2.} This problem involves the bus ridership example in Section
2.11.

\begin{itemize}

\item [(a)] (20) Find the probability that no passengers board the bus at
the first three stops.

\item [(b)] (20) Suppose it is observed that the bus arrives empty at the
third stop.  What is the probability that exactly two people boarded the
bus at the first stop?

\item [(c)] (20) Suppose we wish to find $E(L_2)$ via simulation, by
modifying the program on p.24.  Say we initialize to 0 a variable named
{\bf tl2} near the beginning of the program, and will divide it by {\bf
nreps} near the end of the code.  State the line number after which the
new line is to be inserted, and state what code goes there.  

\end{itemize}

{\bf Solutions:}

{\bf 1.a} {\bf nreps}

{\bf 1.b}  After line 29, insert

\begin{lstlisting}
if (numsend == 2) ce2 <- ce2 + 1
\end{lstlisting}

{\bf 2.a} 

\begin{lstlisting}
0.5^3
\end{lstlisting}

{\bf 2.b}  The event of the bus arriving empty at stop 3 is the same as
$L_2 = 0$.  Then we have:

\begin{eqnarray}
P(B1 = 2 | L_2 = 0) &=& 
\frac{P(B_1 = 2 \textrm{ and } L_2 = 0)}{P(L_2 = 0)} \\
&=& 0.1 * 0.2^2 * 0.5 / 0.292
\end{eqnarray}

where the numbers in the last step come from p.19.

{\bf 2.c}  After line 12, insert:

\begin{lstlisting}
if (j == 2) tl2 <- tl2 + passengers
\end{lstlisting}

\end{document}

