Strategies for Choosing a Prize Box: Stick or Switch?, Slides of Artificial Intelligence

Two strategies for choosing a prize box in a game where only one contains the grand prize. The first strategy is to stick with your initial choice, while the second strategy is to switch with the remaining box. The document also includes examples of shell programming and javascript code for simulating the game and counting the frequency of winning with each strategy.

Typology: Slides

2012/2013

Uploaded on 04/24/2013

banani
banani 🇮🇳

4.3

(3)

91 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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!
Docsity.com
pf3

Partial preview of the text

Download Strategies for Choosing a Prize Box: Stick or Switch? and more Slides Artificial Intelligence in PDF only on Docsity!

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!

Strategy 2: Switch

  • You switch your initial choice P with the remaining box.
  • If ( P = B ) then you lose, else you win!

Strategy 2: switch

b=gen-random p=gen-random if [ $b = $p ] then echo no else echo yes fi

  • Run this many times to count the frequency of yes

Shell Programming Summary

  • numbers and names (strings)
  • shell variables, assignments, substitutions
  • conditions
  • loops (while, for)
  • That’s all that is ever needed for a programming language, really
  • In practice, fairly limited

Javascript

  • More powerful … in the sense that we can write less and do more
  • Run within the browser
  • Embedded in the HTML web pages (to tell the browser how to produce this page)

The

The document object

  • document refers to the webpage to be produced by the browser Š The web browser downloads the html source, but need to produce the document on the screen
  • document.write(…); Š write is a method, or action, that a document can perform. Š … is the parameter that provides data to the action Š it is really the same as directly typing … into the html source, but more flexible – allow us to do computation!