#Jellybeans
#make a jar of jellybeans
black <- rep(0, 999)
red <- 1
number_of_beans <- 5 #beans
jar <- c(black, red)
jar
#how many time would we have to grab a fistful of
#beans before we get the red one?
fistful <- sample(jar, number_of_beans)
counter = 1
while (sum(fistful) == 0) {
fistful <- sample(jar, number_of_beans)
counter <- counter + 1
}
paste("we got the red in", counter, "tries", sep= " ")
#repeat the experiment 1000 times
trys_till_red <- NA
for (i in 1:1000){
fistful <- sample(jar, number_of_beans)
counter = 1
while (sum(fistful) == 0) {
fistful <- sample(jar, number_of_beans)
counter <- counter + 1}
trys_till_red[i] <- counter
}
hist(reds, breaks=30)