A Test Of Sphinx Cut and Paste

This is a test of dumping a cut-and-paste of body text from a sphinx-generated html page.
This is a puzzle from [RTNS].

The Puzzle

A Spanish treasure fleet of three ships was sunk off the coast of Mexico:
  • One had a trunk of gold forward and a trunk of gold aft
  • One had a trunk of gold forward and a trunk of silver aft
  • One had a trunk of silver forward and a trunk of silver aft
Divers just found one of the ships and a trunk of silver in it.
  • What is the probability that the other trunk has silver?

A Reasoning

The way to think of this is to not think of each category (silver vs gold) but to identify each trunk and how it is paired with another trunk. For example, we have six trunks:
G_1, G_2, G_3, S_1, S_2, S_3
In the three ships they were paired up:
  • Ship_1 = \{G_1, G_2\}
  • Ship_2 = \{G_3, S_1\}
  • Ship_3 = \{S_2, S_3\}
The trunk found had silver so the ship was either Ship_2 or Ship_3 and the trunk was one of S_1, S_2, \textrm{or} S_3. Call the trunk found T_f.
  • Case 1: T_f = S_1 then the other trunk will be G_3
  • Case 2: T_f = S_2 then the other trunk will be S_3
  • Case 3: T_f = S_3 then the other trunk will be S_2
In 2 out of 3 cases the trunk will be silver and in 1 out of 3 cases the trunk will be gold. So the probability that the next trunk pulled up (from the same ship) will be silver will be 2/3.

Simulation

This is the method the book gives:
  1. Create three urns: {7,7}, {7,8}, and {8,8}
  2. Choose an urn at random and a random element from the chosen urn
  3. If the element chosen was an 8 (gold), do nothing, if it was a 7 continue
  4. Record the other element in the chosen urn
  5. Calculate the proportion of 7s recorded to 8s
This seems confusing at first – we know that the trunk found was silver so ship 1 was not the one found, why include it in the simulation? My guess is that we do not need the third urn since we discard all the cases where it is chosen and we are not using the number of trials to find the probabilities. I think the given method might be a clearer simulation if we were trying to recreate what happened in that it reflects the entire story, but it does not really reflect the puzzle at the point it takes up – after the first trunk is found – so adds unnecessary computation (well, I guess the whole random choice thing is probably doing that anyway).
Try this:
  1. Create two urns: {0,1}, {1,1}
  2. Pick a random urn and an element from it
  3. If the element was a 0, go back a step
  4. Record the remaining element in the urn
  5. calculate the ratio of 1’s to 0’s
This is confusing, he says find the odds, but 2/3 is probability. The odds of finding silver should be 2:1 (he also flip-flops between saying they found silver and gold in the first trunk, but that is another problem – and the book was free, so what the heck).

GOLD = 0
SILVER = 1
ship_2 = (GOLD, SILVER)
ship_3 = (SILVER, SILVER)
fleet = (ship_2, ship_3)
trials = 10**5

# ships is a list of random ships from the fleet
ships = [random.choice(fleet) for trial in xrange(trials)]

# found_trunks is a list of trunk-indices chosen for each ship (the trunk found by the diver)
# although the values are the same as gold and silver (0 and 1)
# in this case they are tuple indices for the trunk-tuples in the ships
found_trunks = [random.randint(0,1) for ship in ships]

# next_trunks is the type of trunk not chosen for found_trunks if found_trunks wasn't gold
# because it's filtered, its length is the count of all cases where the first trunk was silver
next_trunks = [ships[index][(found_trunks[index] + 1) % 2] for index in range(len(ships))
if ships[index][found_trunks[index]] != GOLD]

# silvers is a count of the next_trunks that were silver
silvers = sum(1 for trunk in next_trunks if trunk == SILVER)

print "Probability next trunk is silver: {0:.2f}".format(float(silvers)/len(next_trunks))
print "(Compare to 2/3 = {0:.2f}).".format(2./3) 
 
Probability next trunk is silver: 0.67 (Compare to 2/3 = 0.67).