Skip to content

Instantly share code, notes, and snippets.

@cjbayesian
Created April 7, 2013 22:16
Show Gist options
  • Save cjbayesian/5332795 to your computer and use it in GitHub Desktop.
Save cjbayesian/5332795 to your computer and use it in GitHub Desktop.
## Simulate Grime Dice ##
red<-c(4,4,4,4,4,9)
blue<-c(2,2,2,7,7,7)
olive<-c(0,5,5,5,5,5)
yellow<-c(3,3,3,3,8,8)
magenta<-c(1,1,6,6,6,6)
## Play n match-ups between d1 and d2
## Return the proportion of d1 victories
roll_dice<-function(d1,d2,n=1)
{
d1rolls<-sample(d1,n,replace=T)
d2rolls<-sample(d2,n,replace=T)
return(mean(d1rolls > d2rolls))
}
# Single Roll
roll_dice(red,blue)
# Average wins
roll_dice(red,blue,n=1000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment