Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fliprou <- function(x,y){
- win10 <- 0
- lose10 <- 0
- win20 <- 0
- lose20 <- 0
- win30 <- 0
- lose30 <- 0
- win40 <- 0
- lose40 <- 0
- ite <- 0
- result2 <- c(0)
- multi <- matrix(c(-5,-2,-0.5,0,1,1,1,1),4,2)
- while (ite < x) {
- ruleta <- c(1,2,4,6,8,10,12)
- proba <- c(4/19,2/19,3/19,3/19,5/19,1/19,1/19)
- fw <- sample(x = ruleta,size = 1,TRUE,proba)
- tiempo <- c(10,20,30,40)
- probtime <- c(0.10,0.50,0.20,0.10)
- t<-sample(tiempo,1,TRUE,probtime)
- ft<-rpois(n=1, lambda=y)
- if(t==10) {
- if((t/ft)>fw) {win10 <- win10+1}
- else {lose10 <- lose10+1}
- ite <- ite+1
- }
- if(t==20) {
- if((t/ft)>fw) {win20 <- win20+1}
- else {lose20 <- lose20+1}
- ite <- ite+1
- }
- if(t==30) {
- if((t/ft)>fw) {win30 <- win30+1}
- else {lose30 <- lose30+1}
- ite <- ite+1
- }
- if(t==40) {
- if((t/ft)>fw) {win40 <- win40+1}
- else {lose40 <- lose40+1}
- ite <- ite+1
- }
- result <- matrix(c(win10,lose10,win20,lose20,win30,lose30,win40,lose40),nrow = 4,ncol = 2, TRUE)
- result1 <- sum(result*multi)
- result2 <- c(result2,result1)
- }
- out <- matrix(c(win10,lose10,win20,lose20,win30,lose30,win40,lose40),nrow = 4,ncol = 2, TRUE)
- ##return(out)
- ejex <- 0:x
- ##plot(ejex,result2,xlab = "Games",ylab = "Profit")
- return(sum(out*multi))
- }
- simul <- function(x,y) {
- return(fliprou(x,y)/x)
- }
- average <- function(x,y) {
- sum <- 0
- for(i in 1:x) {
- sum=sum+simul(1,y)
- }
- return(sum/x)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement