Skip to content

Instantly share code, notes, and snippets.

@jeremyselan
Last active August 24, 2019 06:41
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 jeremyselan/e09aa3f79d7d8d0ae0b7745e5dd27c0e to your computer and use it in GitHub Desktop.
Save jeremyselan/e09aa3f79d7d8d0ae0b7745e5dd27c0e to your computer and use it in GitHub Desktop.
import random, math
def test2(nReal, nFake, nSamples = 100):
numToSample = int(math.ceil( (nReal + nFake) * 0.05 ))
values = range(nReal + nFake)
numTimesCaught = 0
total = 0.0
for test in xrange(nSamples):
random.shuffle( values )
caught = False
for val in values[:numToSample]:
if val < nFake and random.random() < 0.25:
caught = True
break
if not caught:
total += nReal + nFake
else:
numTimesCaught += 1
avg = total / float(nSamples)
print nFake, numToSample, numTimesCaught / float(nSamples), avg * 100.0 - 2500.0
NUMTRIES = 1000000
#for fakePerTurn in xrange(200):
for fakePerTurn in (15, 35, 55, 75, 95, 115):
test2( 25, fakePerTurn, NUMTRIES)
""""
RESULT assuming 25 real bills.
NOTE: YOU DO WORSE USING YOUR REAL MONEY!!! See below.
num fakes, bills sampled, fraction of times caught, expected return
15 2 0.179499 782.004
35 3 0.376754 1239.476
55 4 0.5311 1251.2
75 5 0.64598 1040.2
95 6 0.734229 689.252
115 7 0.799724 303.864
"""
@jeremyselan
Copy link
Author

jeremyselan commented Aug 24, 2019

I also tested combinations where you hold back some of your real bills (guaranteed return on a partial wager, even if caught).

num fake, num real, bills sampled, fraction of times caught, expected return
0 20 1 0.24855 $1502.9
1 19 1 0.23883 1422.34
2 18 1 0.22668 1346.64
3 17 1 0.21082 1278.36
4 16 1 0.20095 1198.1
5 15 1 0.18621 1127.58
6 14 1 0.17529 1049.42
7 13 1 0.16235 975.3
8 12 1 0.14874 902.52
9 11 1 0.13774 824.52
10 10 1 0.12481 750.38
11 9 1 0.11352 672.96
12 8 1 0.098 604.0
13 7 1 0.08864 522.72
14 6 1 0.07421 451.58
15 5 1 0.06352 372.96
16 4 1 0.04934 301.32
17 3 1 0.038 224.0
18 2 1 0.02487 150.26
19 1 1 0.01274 74.52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment