Sleeping Beauty problem: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add CLU) |
ReeceGoding (talk | contribs) (Added R.) |
||
Line 723: | Line 723: | ||
or approximately: 1/3 |
or approximately: 1/3 |
||
</pre> |
</pre> |
||
=={{header|R}}== |
|||
There's nothing complicated here. Pretty much every language that resembles C is going to use virtually the same solution. |
|||
<lang 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))</lang> |
|||
{{out}} |
|||
<pre>[1] 0.3335838</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |