In Las Vegas, a roulette wheel has 38 slots 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 dollar on red, you win 1 dollar if the ball stops in a red slot and otherwise you lose 1 dollar. Write a program to find the total winnings for a player who makes 1000 bets on red.
# Here's a number for each slot
# 1 - 35 odd are red
# 2 - 35 even are black
# 37 - 38 are green
slots <- seq(1,38)
# The number of rounds played
plays <- 1000
# Count wins
hits <- 0
# Loop plays
for (i in 1:plays) {
# The number where the ivory ball lands in this round
pocket <- sample(slots, 1)
# Win if number is red
if (pocket < 36 & pocket %% 2 == 1) {
hits <- hits + 1
}
}
# Results after 1000 plays
(balance <- 1000 - 1000 + (2 * hits))
## [1] 926
# Method 2
# Get outcomes of 1000 plays
outcomes <- sample(slots, plays, T)
# The number of reds times 2, or the prize amount
sum(outcomes < 36 & outcomes %% 2 == 1) * 2
## [1] 992