Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.35 KB | None | 0 0
  1.  
  2. fliprou <- function(x,y){
  3. win10 <- 0
  4. lose10 <- 0
  5. win20 <- 0
  6. lose20 <- 0
  7. win30 <- 0
  8. lose30 <- 0
  9. win40 <- 0
  10. lose40 <- 0
  11. ite <- 0
  12. result2 <- c(0)
  13. multi <- matrix(c(-5,-2,-0.5,0,1,1,1,1),4,2)
  14. while (ite < x) {
  15. ruleta <- c(1,2,4,6,8,10,12)
  16. proba <- c(4/19,2/19,3/19,3/19,5/19,1/19,1/19)
  17. fw <- sample(x = ruleta,size = 1,TRUE,proba)
  18. tiempo <- c(10,20,30,40)
  19. probtime <- c(0.10,0.50,0.20,0.10)
  20. t<-sample(tiempo,1,TRUE,probtime)
  21. ft<-rpois(n=1, lambda=y)
  22. if(t==10) {
  23. if((t/ft)>fw) {win10 <- win10+1}
  24. else {lose10 <- lose10+1}
  25. ite <- ite+1
  26. }
  27. if(t==20) {
  28.   if((t/ft)>fw) {win20 <- win20+1}
  29.   else {lose20 <- lose20+1}
  30.   ite <- ite+1
  31. }
  32. if(t==30) {
  33.   if((t/ft)>fw) {win30 <- win30+1}
  34.   else {lose30 <- lose30+1}
  35.   ite <- ite+1
  36. }
  37. if(t==40) {
  38.   if((t/ft)>fw) {win40 <- win40+1}
  39.   else {lose40 <- lose40+1}
  40.   ite <- ite+1
  41. }
  42. result <- matrix(c(win10,lose10,win20,lose20,win30,lose30,win40,lose40),nrow = 4,ncol = 2, TRUE)
  43. result1 <- sum(result*multi)
  44. result2 <- c(result2,result1)
  45.  
  46. }
  47.  
  48. out <- matrix(c(win10,lose10,win20,lose20,win30,lose30,win40,lose40),nrow = 4,ncol = 2, TRUE)
  49. ##return(out)
  50. ejex <- 0:x
  51. ##plot(ejex,result2,xlab = "Games",ylab = "Profit")
  52. return(sum(out*multi))
  53. }
  54.  
  55. simul <- function(x,y) {
  56.   return(fliprou(x,y)/x)
  57. }
  58.  
  59. average <- function(x,y) {
  60.   sum <- 0
  61.   for(i in 1:x) {
  62.     sum=sum+simul(1,y)
  63.   }
  64.   return(sum/x)
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement