nrepl <- 10000 startwealth <- 100 goal <- 500 #prepare placeholders finalwealth <- numeric(nrepl) lengthofplay <- numeric(nrepl) for(i in 1:nrepl){ wealth=startwealth play=0 while (wealth>0 & wealth0),median(lengthofplay))) #some more fun information #print(c(mean(finalwealth/startwealth)-1,-1/37)) #boxplot(lengthofplay) #other bets to try #wage=min((goal-wealth)*(betnumber/(36-betnumber)),wealth) #bet exactly the amount needed to get to the goal