# Letter in the table with 8 trays

Here is a problem: we have a table with 8 trays. With probability $0.5$, there is a letter somewhere in the table. What is the probability that there is a letter in a last tray, given that there is no letter in first 7 trays?

It looks trivial, but now I'm really confused. Here is how I solved it: let $A$ be the probability that there is a letter in a table (so $P(A) = 0.5$); let $B_i$ be the probability that there is a letter in i-th tray; we need the probability $P(B_8 | \overline{B}_{1-7}) = P(B_8|A\overline{B}_{1-7}) * P(A) + P(B_8|\overline{A}\overline{B}_{1-7}) * P(\overline{A})$. $P(B_8|\overline{A}\overline{B}_{1-7})$ is $0$ (because there is no letter in the table at all), and $P(B_8|A\overline{B}_{1-7})$ is $1$, because we know that the letter is in the table and there is no letter in first 7 trays. So $1*0.5 + 0*0.5 = 0.5$.

But then I've tried a simulation:

#!/usr/bin/python

import random

test_n = 100000

table_empty = [False for x in xrange(8)]

suitable = 0
letter_in_last = 0
for i in xrange(test_n):
has_letter = random.random() >= 0.5
table = table_empty[:]
if has_letter:
table[random.randint(0,7)] = True

if any(table[:7]):
continue # there is a letter in 7 first trays
else:
suitable += 1
if table[-1]:
letter_in_last +=1

print "made %s tests" % test_n
print "%s haven't a letter in first 7 trays" % suitable
print "%s have a letter in last tray" % letter_in_last
print "probability: %s" % (1.0 * letter_in_last / suitable)


And results are like this:

made 100000 tests
56291 haven't a letter in first 7 trays
6185 have a letter in last tray
probability: 0.109875468547


Where is my mistake?

-

There are 9 possibilities. Either there is no letter anywhere (probability $0.5$), or there is a letter in one specific drawer with uniform probability $\frac{1}{16}$. The fact that the first seven drawers had no letters eliminates seven of the nine options, and we're stuck with No Letter with weight $0.5$, and Letter In Last Drawer with weight $0.0625$. All in all, a $12.5\%$ probability that there is a letter in the last drawer.
Edit: The reasoning here is that once the probabilities are fixed in the beginning of my reasoning, we stop thinking of them as absolute probabilities, and rather as weights. The moment we open an empty drawer, that drawer's weight becomes $0$, but the weight of the other possibilities remains unchanged. The moment we open a drawer with a letter, all other weights becomes $0$. Then the ratio of a weight to the total weight is the probability that the letter is in a specific location (be it a drawer or in non-existence).
Your equation $P(B_8 | \overline{B}_{1-7}) = P(B_8|A\overline{B}_{1-7}) P(A) + P(B_8|\overline{A}\overline{B}_{1-7}) P(\overline{A})$ is wrong. The left-hand side is conditioned on $\overline{B}_{1-7}$, and this condition is missing in $P(A)$ and $P(\overline{A})$. The correct equation is $P(B_8 | \overline{B}_{1-7}) = P(B_8|A\overline{B}_{1-7}) P(A| \overline{B}_{1-7}) + P(B_8|\overline{A}\overline{B}_{1-7}) P(\overline{A}| \overline{B}_{1-7})$, but that's not very useful for solving the problem since we don't know $P(A| \overline{B}_{1-7})$ and $P(\overline{A}| \overline{B}_{1-7})$.