2024 Western States 100 Lottery
Introduction
{ What is the lottery? }
Lottery Entrants
Code
# number of people with the respective number of tickets
# this will change year-to-year
<- 4122
one <- 2461
two <- 1472
four <- 870
eight <- 441
sixteen <- 319
thirtytwo <- 202
sixtyfour <- 84
onetwentyeight <- 21
twofiftysix <- 1
fivetwelve
# create unique IDs for each individual
<- (1:one)
tix001 <- (1:two) + max(tix001)
tix002 <- (1:four) + max(tix002)
tix004 <- (1:eight) + max(tix004)
tix008 <- (1:sixteen) + max(tix008)
tix016 <- (1:thirtytwo) + max(tix016)
tix032 <- (1:sixtyfour) + max(tix032)
tix064 <- (1:onetwentyeight) + max(tix064)
tix128 <- (1:twofiftysix) + max(tix128)
tix256 <- (1:fivetwelve) + max(tix256)
tix512
# create the lottery tickets (entrants can have >1 ticket)
<- c(rep(tix001,1),
tickets rep(tix002,2),
rep(tix004,4),
rep(tix008,8),
rep(tix016,16),
rep(tix032,32),
rep(tix064,64),
rep(tix128,128),
rep(tix256,256),
rep(tix512,512))
{ Insert table here }
Number of entrants: 9993
Number of tickets: 68724
Simulation Results
Code
# initialize the simulation
# these counters for the number of simulations in which a person with that number of tickets is selected
= 0
counter001 = 0
counter002 = 0
counter004 = 0
counter008 = 0
counter016 = 0
counter032 = 0
counter064 = 0
counter128 = 0
counter256 = 0
counter512
# number of simulations
= 1000
n_sim
# simulation for loop
for (i in 1:n_sim) {
<- c()
winners while(length(winners)<271) {
<- sample(tickets, size = 1, replace = F)
selection <- unique(c(winners,selection))
winners
}if (sum(tix001[1] %in% winners)>0) {
= counter001 + 1
counter001
}if (sum(tix002[1] %in% winners)>0) {
= counter002 + 1
counter002
}if (sum(tix004[1] %in% winners)>0) {
= counter004 + 1
counter004
}if (sum(tix008[1] %in% winners)>0) {
= counter008 + 1
counter008
}if (sum(tix016[1] %in% winners)>0) {
= counter016 + 1
counter016
}if (sum(tix032[1] %in% winners)>0) {
= counter032 + 1
counter032
}if (sum(tix064[1] %in% winners)>0) {
= counter064 + 1
counter064
}if (sum(tix128[1] %in% winners)>0) {
= counter128 + 1
counter128
}if (sum(tix256[1] %in% winners)>0) {
= counter256 + 1
counter256
}if (sum(tix512[1] %in% winners)>0) {
= counter512 + 1
counter512
}
}
# output table of results
::kable(
knitrdata.frame(
`Number of tickets` = c(
"1 ticket", "2 tickets", "4 tickets", "8 tickets", "16 tickets",
"32 tickets", "64 tickets", "128 tickets", "256 tickets", "512 tickets"),
`Percent Chance` = c(
paste0(format(round(counter001*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter002*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter004*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter008*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter016*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter032*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter064*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter128*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter256*100/n_sim,2),nsmall=2),"%"),
paste0(format(round(counter512*100/n_sim,2),nsmall=2),"%")
)
) )
Number.of.tickets | Percent.Chance |
---|---|
1 ticket | 0.20% |
2 tickets | 1.20% |
4 tickets | 1.30% |
8 tickets | 2.90% |
16 tickets | 7.10% |
32 tickets | 12.60% |
64 tickets | 26.30% |
128 tickets | 44.70% |
256 tickets | 66.20% |
512 tickets | 88.80% |