# Enigmatic Code

Programming Enigma Puzzles

## Tantalizer 428: Sisters of mercy

From New Scientist #979, 11th December 1975 [link]

Faith, Hope and Charity had “adopted” an old couple in their neighbourhood and a random one of the drops in each morning to jolly things along. Tom and Annie, the oldsters, take it in good part, especially since they started having a flutter on who the next ministering angel will be.

“Tell you what”, Tom proposed slyly one evening, “Let’s have an extra bet. Who do you bet it will be for the next two days?”
“Faith both days”, said Annie.
Tom replied, “And I bet it will be Hope, followed by Faith. £1?”
“Very well”, said Annie, “but what if we are both wrong?”
“Then the bet stands until such time as Faith arrives either for the second day running (and you win) or on the day after Hope (and I win).”
“Done”, said Annie.

What are Tom’s chances of winning?

[tantalizer428]

### One response to “Tantalizer 428: Sisters of mercy”

1. Jim Randell 29 May 2019 at 8:04 am

This is a version of Penney’s Game (see: Enigma 287), but using a “three sided coin”.

We can solve it by considering variables of the form:

P(s) = the probability of HF occurring before FF, given we have seen a sequence s

We can construct expressions for each possible sequence s, i.e.:

P([]) = (P(F) + P(H) + P(C)) / 3
P(F) = (P(FF) + P(FH) + P(FC)) / 3
P(FH) = (P(HF) + P(HH) + P(HC)) / 3

P(FF) = 0
P(HF) = 1

And then solve the 13 equations in 13 variables using the Gaussian elimination solver [[ `matrix.linear()` ]] from the enigma.py library (which was originally written for Enigma 287). The answer is then the value of P([]).

The program runs in 91ms.

Run: [ @repl.it ]

```from fractions import Fraction as F
from enigma import matrix, printf

# probability of any particular "angel" is 1/3
p = F(-1, 3)
q = 1 + p

# 13 equations in 13 variables
eqs = [
# [] F  H  C FF FH FC HF HH HC CF CH CC
( 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ), # P(HF) = 1
( 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 ), # P(FF) = 0
( 1, p, p, p, 0, 0, 0, 0, 0, 0, 0, 0, 0 ),
( 0, 1, 0, 0, p, p, p, 0, 0, 0, 0, 0, 0 ),
( 0, 0, 1, 0, 0, 0, 0, p, p, p, 0, 0, 0 ),
( 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, p, p, p ),
( 0, 0, 0, 0, 0, 1, 0, p, p, p, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, p, p, p ),
( 0, 0, 0, 0, 0, 0, 0, p, q, p, 0, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, p, p, p ),
( 0, 0, 0, 0, p, p, p, 0, 0, 0, 1, 0, 0 ),
( 0, 0, 0, 0, 0, 0, 0, p, p, p, 0, 1, 0 ),
( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, p, p, q ),
]

# solve the equations to give the probabilities
s = matrix.linear(eqs, [1] + [0] * (len(eqs) - 1))

# solution is P([])
printf("P([]) = {s[0]}")
```

Solution: Tom’s chance of winning is 2/3.

When the solution was published Martin Hollis commented:

“Having set this puzzle, I could not solve it (!)”

This site uses Akismet to reduce spam. Learn how your comment data is processed.