Set you criteria, run the code, see if you got b8ed.
Step 1
# Roulette
# Set criteria
buy_in <- 40
max_spins <- 10
Step 2
spin <- 1
total <- 40
while(total > 0 & max_spins > spin){
# Make bet
total <- total - 40
colour <- sample(c('black','red'),1)
red_numbers<-as.character(c(1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36))
black_numbers<-as.character(c(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 28, 29, 31, 33, 35))
if(colour[1]=='black'){
bet <- c(colour,
sample(red_numbers,10))
}else{
bet <- c(colour,
sample(black_numbers,10))
}
# Spin wheel
winning_number <- as.character(sample(c(0,'00',1:32),1))
# Pay out
if(winning_number %in% bet){
total <- total + 72
}else{
if(colour == 'black'){
if(winning_number %in% black_numbers){
total <- total + 40
}else{
total <- total - 40
}
}else{
if(winning_number %in% red_numbers){
total <- total + 40
}else{
total <- total - 40
}
}
}
print(paste0('spin: ',spin))
print(paste0('total: $',total))
spin <- spin + 1
}
## [1] "spin: 1"
## [1] "total: $-40"