RosettaCodeData/Task/Sleeping-Beauty-problem/R/sleeping-beauty-problem.r
2023-07-01 13:44:08 -04:00

11 lines
275 B
R

beautyProblem <- function(n)
{
wakeCount <- headCount <- 0
for(i in seq_len(n))
{
wakeCount <- wakeCount + 1
if(sample(c("H", "T"), 1) == "H") headCount <- headCount + 1 else wakeCount <- wakeCount + 1
}
headCount/wakeCount
}
print(beautyProblem(10000000))