7 Another form of bet for roulette is to bet that a specific number (say 17) will turn up. If the ball stops on your number, you get your dollar back plus 35 dollars. If not, you lose your dollar. Write a program that will plot your winnings when you make 500 plays of roulette at Las Vegas, first when you bet each time on red (see Exercise 6), and then for a second visit to Las Vegas when you make 500 plays betting each time on the number 17. What differences do you see in the graphs of your winnings on these two occasions?

# Betting on red first
# Function that runs # number of plays and sees if ball lands on red
on_red <-function(plays) {
  bankroll <- c(1)
  for (i in 1:plays) {
    slot <- sample(1:38,1)
    if (slot <= 18) {
      bankroll[i + 1] <- bankroll[i] + 1}
    else {bankroll[i + 1] <- bankroll[i] - 1}
  }
  return(bankroll)
}
# Run function with 500 plays
a <- on_red(500)
# Plot results
plot(a)

#
# Next, betting to land on number 17
# Function that runs # number of plays and sees if ball lands on number 17
num17 <-function(plays) {
  bankroll <- c(1)
  for (i in 1:plays) {
    slot <- sample(1:38,1)
    if (slot == 17) {
      bankroll[i + 1] <- bankroll[i] + 35}
    else {bankroll[i + 1] <- bankroll[i] - 1}
    }
  return(bankroll)
  }
# Run function with 500 plays
b <- num17(500)
# Plot results
plot(b)

The plot for betting on red is a lot like a coin toss only with a persistent downward bias. The plot for betting on number 17 shows steady downward trends with occasional bumps upward (when $35 is won).