
1
CSCI 100
Think Like Computers
Lecture 14
Fall 2008
Last Time …
•There are three prize boxes (A, B, C) and
only one (randomly chosen) contains the
TV show grand prize.
•You’ll pick one out of the three as your
choice.
•After your pick, the TV show host reveals
one empty box from the remaining 2.
•Now, do you stick with your choice, or
switch with the unopened remaining box?
Simulation Setup
•0 1 2 for A B C
•B = Random pick the box containing the
prize
•P = Your random pick
•Both are random numbers from (0,1,2)
Strategy 1: Stick
•You stick with your initial choice P:
•If ( P = B ) then you win, else you lose
Conditional in Shell
•if condition
•then
•command-list
•elif condition
•then
•command-list
•else
•command-list
•fi
Conditional commands
b=`gen-random`
p=`gen-random`
if [ $b = $p ]
then
echo yes
else
echo no
fi
•Run this many times
to count the
frequency of yes
remember the while
loop!