# 現金記錄，起始0元，記錄 100000 次
money.A <- vector("integer", 100000 + 1)
money.A[1] <- 0

for (i in 2:100001) {
  this.buy <- sample(0:9999, 1)
  this.res <- sample(0:9999, 23, replace = T)
  
  money.A[i] <- money.A[i - 1] - 1 # 花1元買票
  
  # 是否中各個奬項的判斷
  is.p1 <- this.buy == this.res[1]
  is.p2 <- this.buy == this.res[2]
  is.p3 <- this.buy == this.res[3]
  is.p4 <- any(this.buy == this.res[4:13]) # any()表示只要一個true就是true
  is.p5 <- any(this.buy == this.res[14:23])
  is.noPrice <- !any(c(is.p1, is.p2, is.p3, is.p4, is.p5))
  this.prize <-
    as.character(which(c(
      is.p1, is.p2, is.p3, is.p4, is.p5, is.noPrice
    )))
  # this.prize回傳只能是1/2/3/4/5/6其中之一，分別表示這張票的六種可能結果
  
  # A組情況
  money.A[i] <-
    switch(
      this.prize,
      "1" = money.A[i] + 2500,
      "2" = money.A[i] + 2000,
      "3" = money.A[i] + 1500,
      "4" = money.A[i] + 250,
      "5" = money.A[i] + 150,
      "6" = money.A[i] + 0,
    )
  
}

print(money.A)
plot(money.A, type = "l")
