TITLE: Problem 2: Flip a Coin
AUTHOR:  Hans Petter Langtangen Email: hpl@simula.no at Center for Biomedical Computing, Simula Research Laboratory & Department of Informatics, University of Oslo
DATE:  today

# Logical name of exercise: flip_coin
# This document might contain references to a parent document (../testdoc).
# These references will work for latex (using the xr package and
# a compiled parent document (with ../testdoc.aux file), but other formats
# might have missing references.
# Externaldocuments: ../testdoc


# keywords = random numbers; Monte Carlo simulation; ipynb

# Torture tests

#--- begin subexercise ---
__a)__
Make a program that simulates flipping a coin $N$ times.
Print out ``tail'' or ``head'' for each flip and
let the program count the number of heads.


__Hint 1.__
Use `r = random.random()` and define head as `r <= 0.5`.



__Hint 2.__
Draw an integer among $\{1,2\}$ with
`r = random.randint(1,2)` and define head when `r` is 1.






#--- end subexercise ---

#--- begin subexercise ---
__b)__
Vectorize the code in a) using boolean indexing.

Vectorized code can be written in many ways.
Sometimes the code is less intuitive, sometimes not.
At least there is not much to find in Section ref{sec1}.

#--- end subexercise ---

#--- begin subexercise ---
__c)__
Vectorize the code in a) using `numpy.sum`.



In this latter subexercise, we have an
example where the code is easy to read.


=== My remarks ===

Remarks with such a subsubsection is treated as more text
after the last subexercise. Test a list too:

 o Mark 1.
 o Mark 2.

#--- end subexercise ---



# Closing remarks for this Problem

=== Remarks ===

These are the exercise remarks, appearing at the very end.

# solution files: mysol.txt, mysol_flip_coin.py, yet_another.file
