Sunday Times Teaser 3068 – Valued Playwrights
by Victor Bryant
Published Sunday July 11 2021 (link)
I have given each letter of the alphabet a different whole-number value from 1 to 26. For example, P=4, L=8, A=3 and Y=24. With my numbers I can work out the value of any word by adding up the values of its letters, for example the word PLAY has a value of 39.
It turns out that the playwrights:
BECKETT, FRAYN, PIRANDELLO, RATTIGAN, SHAKESPEARE and SHAW
all have the same prime value.
Also COWARD, PINERO and STOPPARD have prime values.
What are these three prime numbers?
3 Comments
Leave one →
Runs in 75 milliseconds in CPython on my Intel I9 ‘Coffee Lake’ laptop.
@Brian, The order of checks seems to be pretty efficient. I tried to do the is_prime(shaw) and is_prime(pinero) checks as soon as possible but that didn’t make it faster.
@Frits I did try several evaluation orders and this was was far better than the others I tried. In my first (rough) version, I used none of the word relationships other than the common prime and this was very slow on CPython but tolerable on PyPy (~300 milliseconds). Having got to 70 milliseconds on CPython with the version above, I was surprised to find that it was actually slower on PyPy. It will be interesting to see what manual solvers come up with in terms of evaluation order.