Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PlayGame <- function(winnings=0, turn=1) {
- if(sample(0:1, 1)) {
- winnings <- winnings + (2^turn)
- turn <- turn + 1
- PlayGame(winnings, turn)
- }
- else {
- winnings
- }
- }
- RunSimulation <- function(timesToPlay=20000) {
- results <- rep(NA, timesToPlay)
- results1 <- rep(NA, timesToPlay)
- rollingAvg <- rep(NA, timesToPlay)
- rollingAvg1 <- rep(NA, timesToPlay)
- for(i in 1:timesToPlay) {
- results[i] <- PlayGame()
- results[i] = results[i]
- rollingAvg[i] <- mean(results[1:i])
- }
- plot1 = plot(rollingAvg, type="l")
- }
- RunSimulation()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement