Skip to main content
guest
Join

Help

Sign In
thinkatorium.wikispaces.com
Home
guest

Join

Help

Sign In
Wiki Home
Recent Changes
Pages and Files
Members
Habits for Student Success
NPHS Home Page
Algebra 2 CP
Statistics with Technology
Math and Family Support
Flipped Classroom (Classroom Policies)
Corona SDK
Robotics Club
Statistics Snippets
Blogs and Podcasts
Clickers
Interesting Books for Teachers
Math Organizations
Common Core Links
Revolutionary Apps for the Classroom
Online LaTeX Equation Editor
Flipped Resources
Simulating Craps with R
Edit
0
2
…
0
Tags
No tags
Notify
RSS
Backlinks
Source
Print
Export (PDF)
passLineBet < function(n.sim){
makepoint < function ( point ) {
made < NA
while ( is.na(made) ) { # roll until outcome is determined
roll < sum ( sample ( 6, 2, replace=T ) )
if ( roll == point ) {
made < TRUE
} else if ( roll == 7 ) {
made < FALSE
}
} # end while
return ( made )
} # end makepoint
sim.craps < function () {
wonFirstRoll = 0
lostFirstRoll = 0
wonPoint = 0
lostPoint = 0
roll < sum ( sample ( 6, 2, replace=T ) )
if ( roll==7  roll==11 )
{
win < T
cat("won on ",roll,"\n")
wonFirstRoll = wonFirstRoll + 1
}
else if ( roll==2  roll==3  roll==12 )
{
win < F
cat("lost on ",roll,"\n")
lostFirstRoll = lostFirstRoll + 1
}
else
win < makepoint ( roll )
if(win)
{
cat("won on point ",roll,"\n")
wonPoint = wonPoint + 1
}
else
{
cat("lost on point ",roll,"\n")
lostPoint = lostPoint + 1
}
stuff < c(win,wonFirstRoll,lostFirstRoll,wonPoint,lostPoint)
return ( stuff )
}
#n.sim < 100000
wins < 0
wonFirstRoll = 0
lostFirstRoll = 0
wonPoint = 0
lostPoint = 0
for ( i in 1:n.sim )
{
stuff = sim.craps()
wonFirstRoll = wonFirstRoll + stuff[2]
lostFirstRoll = lostFirstRoll + stuff[3]
wonPoint = wonPoint + stuff[4]
lostPoint = lostPoint + stuff[5]
}
cat("wonFirstRoll: ",wonFirstRoll," lostFirstRoll: ",lostFirstRoll," wonPoint: ",wonPoint," lostPoint: ",lostPoint)
#wins < wins + sim.craps()
( wins/n.sim )
}
Javascript Required
You need to enable Javascript in your browser to edit pages.
help on how to format text
Turn off "Getting Started"
Home
...
Loading...
makepoint < function ( point ) {
made < NA
while ( is.na(made) ) { # roll until outcome is determined
roll < sum ( sample ( 6, 2, replace=T ) )
if ( roll == point ) {
made < TRUE
} else if ( roll == 7 ) {
made < FALSE
}
} # end while
return ( made )
} # end makepoint
sim.craps < function () {
wonFirstRoll = 0
lostFirstRoll = 0
wonPoint = 0
lostPoint = 0
roll < sum ( sample ( 6, 2, replace=T ) )
if ( roll==7  roll==11 )
{
win < T
cat("won on ",roll,"\n")
wonFirstRoll = wonFirstRoll + 1
}
else if ( roll==2  roll==3  roll==12 )
{
win < F
cat("lost on ",roll,"\n")
lostFirstRoll = lostFirstRoll + 1
}
else
win < makepoint ( roll )
if(win)
{
cat("won on point ",roll,"\n")
wonPoint = wonPoint + 1
}
else
{
cat("lost on point ",roll,"\n")
lostPoint = lostPoint + 1
}
stuff < c(win,wonFirstRoll,lostFirstRoll,wonPoint,lostPoint)
return ( stuff )
}
#n.sim < 100000
wins < 0
wonFirstRoll = 0
lostFirstRoll = 0
wonPoint = 0
lostPoint = 0
for ( i in 1:n.sim )
{
stuff = sim.craps()
wonFirstRoll = wonFirstRoll + stuff[2]
lostFirstRoll = lostFirstRoll + stuff[3]
wonPoint = wonPoint + stuff[4]
lostPoint = lostPoint + stuff[5]
}
cat("wonFirstRoll: ",wonFirstRoll," lostFirstRoll: ",lostFirstRoll," wonPoint: ",wonPoint," lostPoint: ",lostPoint)
#wins < wins + sim.craps()
( wins/n.sim )
}