Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@malmaud
Last active September 29, 2015 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malmaud/3262577086c49dad0f64 to your computer and use it in GitHub Desktop.
Save malmaud/3262577086c49dad0f64 to your computer and use it in GitHub Desktop.
hothand
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