Created
February 9, 2019 01:14
-
-
Save cdsousa/ac8d8d87d45de1a50ca8a6f622e40133 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
###### test 1 | |
function gamblers_falacy_1(n) | |
h,t = 0,0; c=0; r=0 | |
for i=1:n | |
p = t>h ? :h : (h>t ? :t : nothing) | |
o = rand((:h,:t)) | |
c = p==nothing ? c : c+1 | |
r = p==o ? r+1 : r | |
o==:h ? (h+=1) : (t+=1) | |
println("i=$i t=$t h=$h c=$c r=$r rr=$(r/c)") | |
end | |
end | |
## | |
gamblers_falacy_1(1000) | |
######## test 2 | |
function gamblers_falacy_2(n) | |
last = :none | |
number = 0 | |
guesses = Dict{Int,NamedTuple{(:tries, :rights),Tuple{Int64,Int64}}}() | |
for i=1:n | |
if number > 1 | |
guess = last==:h ? :t : :h | |
else | |
guess = nothing | |
end | |
outcome = rand((:h,:t)) | |
if guess != nothing | |
guesstries, guessrigths = get(guesses, number, (0,0)) | |
guesstries += 1 | |
if guess == outcome | |
guessrigths += 1 | |
end | |
guesses[number] = (tries=guesstries, rights=guessrigths) | |
end | |
#println("$last"^number, " $outcome") | |
if outcome == last | |
number += 1 | |
else | |
last = outcome | |
number = 1 | |
end | |
end | |
guesses | |
end | |
## | |
println() | |
guesses = gamblers_falacy_2(1000000) | |
guessesarr = sort([(n, g[:tries], g[:rights], round(g[:rights]/g[:tries], digits=3)) for (n,g) in guesses]) | |
for g in guessesarr | |
println(g) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment