Last active
September 29, 2015 10:45
-
-
Save malmaud/3262577086c49dad0f64 to your computer and use it in GitHub Desktop.
hothand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function simulate(N_trials, N_runs) | |
outcomes=zeros(Bool, N_runs) | |
Σ=0.0 | |
N=0 | |
for trial=1:N_trials | |
pos=0 | |
neg=0 | |
for run=1:N_runs | |
outcomes[run]=rand(Bool) | |
end | |
for run=2:N_runs | |
if outcomes[run-1] | |
if outcomes[run] | |
pos += 1 | |
else | |
neg += 1 | |
end | |
end | |
end | |
if pos+neg>0 | |
Σ += pos/(pos+neg) | |
N +=1 | |
end | |
end | |
Σ/N | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment