### Random Post

### Recent Posts

### Recent Comments

### Archives

### Categories

- article (11)
- enigma (1,502)
- misc (5)
- project euler (2)
- puzzle (90)
- puzzle# (117)
- site news (69)
- tantalizer (158)
- teaser (7)
- today (1)

### Site Stats

- 281,282 hits

Programming Enigma Puzzles

5 July 2021

Posted by on **From New Scientist #1785, 7th September 1991** [link]

My niece (whose age is a two-figure number) is very good at arithmetic, and to keep her occupied on a recent train journey I asked her to find a number with all its digits different and with the sum of its digits a multiple (more than one times) of her age.

She wrote down a list of lots of number with both those properties. So I then asked her to add 1 to each of her numbers, and to pick out from the new list each number which still had all its digits different and with the sum of its digits equal to a multiple (again, more than one times) of her age

birthday.nextThere were still quite a few numbers in this new list which had these properties. So I asked her to find one of them which, when multiplied by her age, gave an answer which

had all its digits different — which she did!stillHow old is she?

[enigma631]

%d bloggers like this:

If we have a number

nthat has a digit sum ofk. Then the digit sum of(n + 1)will be(k + 1)unless the final digit ofnis 9. And if it is, the digit sum will be(k – 9 + 1)=(k – 8).This program looks at sets of digits (as any number formed from those digits in some order will have the same digit sum), that have a digit sum that is a proper multiple of a potential 2-digit age.

And then selects sets that potentially give numbers that, when incremented, will have a digit sum that is a proper multiple of the 2-digit age, also incremented.

Once a potential set is identified we construct corresponding numbers that could appear on the first list (although this will not give an exhaustive list of possibilities for the first list), and from that list derives corresponding numbers that could appear on the second list, and then the third list.

If the third list we get is non-empty, then we have found a solution.

This Python program runs in 538ms.

Run:[ @replit ]Solution:The niece’s age is 11.For instance the final number could be: 2679453810 (which has all its digits different).

And: 2679453810 = 11 × 243586710.

So: 243586710 is a number on the second list. It has all its digits different, and has a digit sum of 36 = 3 × 12, where the niece will be 12 on her next birthday.

The corresponding number on the first list is: 243586709, which has all its digits different, and a digit sum of 44 = 4 × 11, where the niece is currently 11.

(And of course any valid rearrangement of the digits of 243586709 will give a number that could appear on the first list).

In fact, there are 22 possible numbers that the niece could have given:

The second list could have up to 5,760 numbers on it, and the first list could have up to 533,448 numbers on it.

I am busy with a SubstitutedExpression solver program for this problem, I am not sure if I can make it fast enough to finish within a minute. I noticed you can limit her age to 10-22 as the sum of digits is 45 at most (if a > 22: break).

I have posted a solution to this enigma puzzle here.

Pingback: New Scientist Enigma 631 – Fidget Digit | PuzzlingInPython

Only one age is possible with digital sum of first list number equal to 44 (age 10 is rejected).

I have added code for this special situation.

This Python program runs in approx 40ms.

Impressive speed for a solution using [[

`SubstitutedExpression`

]]. I made a run file that took 6m30s to execute.I stepped through your program in a debugger, and like the fact that if finds the 22 numbers on the third list (and their counterparts on the first two lists), even if it doesn’t display them.

Analysing the potential digit sums (the first 20 lines of my program), tells us that there are only two potential situations:

So it is not necessary to consider numbers on list 1, other than those that end in 9.

And as you point out [1] is non-viable, as the numbers on list 2 must end in 0, and then the number on list 3 would end in 00.

So this leaves [2] as the only possible source of solutions. Here’s my program modified to print the 22 numbers on the third list, and their counterparts on list 1 and 2: