title: “Coin FLip Game”
output: html_document
“`{r setup, include=FALSE}
Copyright By PowCoder代写 加微信 powcoder
knitr::opts_chunk$set(echo = TRUE)
prob <- .5 coinFlip <- function(p){ flip <- rbinom(1,1,p) face <- ifelse(flip == 1, 'H', "T") return(face) ## SImulate one coin flip f <- coinFlip(.5) ## Simulate 20 flips num_Flips <- 200 results <- NULL for (i in 1:num_Flips){ results <- c(results, coinFlip(prob)) barplot(table(results), ylim = c(0, num_Flips)) coinFlipGame <- function(req_diff, cost_per_flip, payoff){ game <- coinFlipGame(3, 1, 8) ##Simulation Trials numTrials <- 10000 Sim <- NULL for (i in 1:numTrials){ game <- coinFlipGame(3, 1, 8) Sim <- rbind(Sim, game) avg_flips <- mean(Sim[, 1]) avg_winnings <- mean(Sim[, 2]) avg_winnings 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com