# 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:Divers just found one of the ships and a trunk of silver in it.

- 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

- 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:In the three ships they were paired up:

The trunk found had silver so the ship was either or and the trunk was one of . Call the trunk found .

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.

- Case 1: then the other trunk will be
- Case 2: then the other trunk will be
- Case 3: then the other trunk will be

## Simulation¶

This is the method the book gives: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).

- Create three urns: {7,7}, {7,8}, and {8,8}
- Choose an urn at random and a random element from the chosen urn
- If the element chosen was an 8 (gold), do nothing, if it was a 7 continue
- Record the other element in the chosen urn
- Calculate the proportion of 7s recorded to 8s

Try this:

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).

- Create two urns: {0,1}, {1,1}
- Pick a random urn and an element from it
- If the element was a 0, go back a step
- Record the remaining element in the urn
- calculate the ratio of 1’s to 0’s

`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)

` `