In Las Vegas, a roulette wheel has 38 slows numbered 0, 00, 1, 2,…,36. The 0 and 00 slots are green and half of the remaining 36 slots are red and half are black. A croupier spins the wheel and throws in an ivory ball. If you bet $1 on red, you win $1 if the ball stops in a red slow and otherwise you lose $1. Write a program to find the total winnings for a player who makes 1000 bets on red.

set.seed(123)

roulette <- function(spin, bet){
  r <- c(1, 3, 5, 7, 9, 12, 14, 16, 18, 21, 23, 25, 27, 28, 30, 32, 34, 36)
  b <- c(2, 4, 6, 8, 10, 11, 13, 15, 17, 20, 22, 24, 26, 29, 31, 33, 35)
  g <- c(37, 38)
  
  wins <- 0
  
  record <- 0
  
  spins <- sample(1:38, spin, replace = TRUE)

  record <- spins %in% r
  wins <- sum(record, na.rm = TRUE)
  wins <-  (2 * wins) - (spin - wins)
  
  return(wins)
}

My gambling is a little rusty, but I assume that “If you bet $1, you win $1” really means you have a net of $2 for a victory. Otherwise you lose whatever you bet. So let’s run a few simulations and see what our profits (if any) are.

try1 <- roulette(1000, 1)
try2 <- roulette(1000, 1)
try3 <- roulette(1000, 1)

try1
## [1] 401
try2
## [1] 425
try3
## [1] 371

We see that the winnings are roughly consistent across multiple attempts.