Teaser 2553: The X-Factor
From The Sunday Times, 28th August 2011 [link] [link]
George and Martha’s daughter entered a singing competition. The entrants were numbered from one upwards. The total number of entrants was a three-digit number and their daughter’s number was a two-digit number. The five digits used in those two numbers were all different and non-zero. Martha noted that the number of entrants was a single-digit multiple of their daughter’s number. George realised the same would be true if the two digits of their daughter’s number were reversed.
How many entrants were there?
[teaser2553]






Jim Randell 8:14 am on 9 May 2025 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.The following run file executes in 84ms. (Internal runtime of the generated code is 10.9ms).
Solution: There were 168 entrants.
The daughter’s number is either 24 or 42.
LikeLike
Frits 3:31 pm on 9 May 2025 Permalink |
I tested that “ediv” is a bit faster than “div” as for “div” an error/exception may occur when comparing “None” with an integer.
LikeLike
Jim Randell 4:19 pm on 9 May 2025 Permalink |
@Frits: [[
ediv()]] throws an error if the division is not exact, whereas [[div()]] returns [[None]].In Python 3 you will get type error if you compare [[
None]] to a number. But in Python 2 [[None]] compares as less than any number (including [[-inf]]). So using [[ediv()]] also allows the run file to work in older versions of Python.LikeLike
Frits 3:18 pm on 10 May 2025 Permalink |
or skipping a loop over “J”.
LikeLike
Jim Randell 8:33 am on 10 May 2025 Permalink |
Or without using [[
*div()]] function calls.This run file has an internal runtime of 188µs.
(Further speed improvements left as a simple exercise for the reader).
LikeLike
Ruud 3:01 pm on 9 May 2025 Permalink |
import peek import istr for daughter in istr(range(10, 100)): for n, m in istr.combinations(range(1, 10), r=2): if ( (entrants := daughter * n) == (daughter_reversed := daughter.reversed()) * m and len(entrants) == 3 and ("0" not in entrants) and (entrants | daughter).all_distinct() and (entrants | daughter_reversed).all_distinct() ): peek(entrants, daughter, daughter_reversed)LikeLike
Frits 4:09 pm on 9 May 2025 Permalink |
@Ruud,
Line 11 doesn’t seem to be logically necessary.
I read the readme of the peek module at your Salabim site. I wish I had known this before. I will have a look at it (I’ll send you an email concerning an installation issue).
I made my own simple debugging tool, I don’t need to import anything as I use preprocessing.
A basic version is described at:
[ https://enigmaticcode.wordpress.com/notes/#comment-10234 ]
LikeLike
ruudvanderham 1:16 pm on 10 May 2025 Permalink |
Yes, you are right. Line 11 could be omitted (although it is not wrong).
Nice to be in contact (in Dutch!) with you on the subject of peek.
LikeLike