-
Notifications
You must be signed in to change notification settings - Fork 0
/
2019-08-26-counterfeit-notes.R
56 lines (31 loc) · 2.13 KB
/
2019-08-26-counterfeit-notes.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
library(tidyverse)
# https://fivethirtyeight.com/features/can-you-fool-the-bank-with-your-counterfeit-bills/
# You are an expert counterfeiter, and you specialize in forging one of the most ubiquitous notes in global circulation, the U.S. $100 bill. You’ve been able to fool the authorities with your carefully crafted C-notes for some time, but you’ve learned that new security features will make it impossible for you to continue to avoid detection. As a result, you decide to deposit as many fake notes as you dare before the security features are implemented and then retire from your life of crime.
#
# You know from experience that the bank can only spot your fakes 25 percent of the time, and trying to deposit only counterfeit bills would be a ticket to jail. However, if you combine fake and real notes, there’s a chance the bank will accept your money. You have $2,500 in bona fide hundreds, plus a virtually unlimited supply of counterfeits. The bank scrutinizes cash deposits carefully: They randomly select 5 percent of the notes they receive, rounded up to the nearest whole number, for close examination. If they identify any note in a deposit as fake, they will confiscate the entire sum, leaving you only enough time to flee.
#
# How many fake notes should you add to the $2,500 in order to maximize the expected value of your bank account? How much free money are you likely to make from your strategy?
mix_money <- function(n){
real <- rep(0, 25)
fake <- rep(1, n)
money_bag <- sample(c(real, fake), 25 + n)
}
inspect_money_bag <- function(money_bag){
selection <- sample(money_bag, size = round(.05 * length(money_bag)))
counterfeits <- sum(selection)
prob_spotting <- 1 - (.75 ^ counterfeits)
spotted_counterfeits <- sample(c(1,0), 1, prob = c(prob_spotting, 1 - prob_spotting))
expected_value <- case_when(
spotted_counterfeits > 0 ~ 0,
TRUE ~ (length(money_bag) * 100)
)
}
try_scenario <- function(n){
n_sims <- 100000
total <- sum(replicate(n_sims, inspect_money_bag(mix_money(n)))) / n_sims
}
ans <- 0:100 %>%
map(try_scenario) %>%
unlist()
plot(c(0:100), ans)
#