From The Sunday Times, 25th May 1980 [link]
Large families often have problems, particularly when it comes to deciding who has first choice, etc.
My six brothers and I solved this particular one by devising our own dice game. Each of us in turn would roll a die four times and put the results together in that order to form a four-figure number. (So that, for example: 6 followed by 2, then 3 and 1, gives the number 6231). We would each do this and the one of us getting the highest four-figure number would be declared the winner.
One such game had some very strange results. Each of us got a different prime number, using the same four different digits. The average of the seven primes was a perfect square, to which Jon’s number was the nearest.
The difference between Ron’s and Don’s numbers, multiplied by one of the numbers from the die, gave the difference between Len’s and Ken’s numbers.
Omitting Ben’s score, the total could have been formed by throwing the die five times. And so could the total of the numbers thrown by Len, Ken, Ron and me.
What was my score, and who ate the biggest piece of apple pie?
The originally published version of this puzzle was flawed, so the version above was taken from the book Microteasers (1986), in which it was noted:
There is an interesting postscript to [this] puzzle. When it first appeared, the condition “each of us got a different prime number using the same four different digits” was given as “each of us got a different prime number; two digits never came up”. That allowed numbers like 5651, which was not the intention at all. The odd thing is that all the readers who sent in answers found the intended solution anyway. So perhaps, even if one relaxes the condition about all the primes using four different digits, the teaser still has a unique solution. The keener reader might like to adapt the program to take four digits in turn and see how many primes can be made from those four (but not necessarily using all four each time). Then you have to consider all possible sets of seven from those. We leave this much harder problem as an exercise.
However the original formulation of the puzzle does not give a unique solution.
[teaser931]
Jim Randell 10:20 am on 5 March 2023 Permalink |
A brute force approach considers 6838 values, which is what the following Python program does.
It runs in 61ms. (Internal runtime is 4.7ms).
Run: [ @replit ]
from enigma import (irange, inf, is_npalindrome, printf) # function to apply f = lambda x: x * (x + 1) # consider possible numbers vs = dict() for n in irange(0, inf): v = f(n) if v < 10000000: continue if v > 100000000: break # is the result a palindrome? if is_npalindrome(v): # have we recorded (n - 22)? v2 = vs.get(n - 22) if v2 is not None: # output solution printf("f({n}) = {v}; f({n2}) = {v2}", n2=n - 22) # record this value vs[n] = vSolution: The numbers are 5291, 5313.
We have:
In fact these are the only two 8-digit palindromes that are the product of 2 consecutive integers.
LikeLike
Jim Randell 10:45 am on 5 March 2023 Permalink |
This puzzle was included in the book Microteasers (1986) by Victor Bryant.
Here is the BBC BASIC program given in the text. It looks for palindromic 8-digit numbers that are the product of two consecutive integers, and prints them out. So it doesn’t look for a pair of numbers that differ by 22.
>LIST 5 REM Victor Bryant program for Teaser 1071 6 REM from "Microteasers" (1986) 10 REM We want N + N^2 to be an 8-digit palindrome 15 start% = TIME 20 N = 3000 30 REPEAT 40 N = N + 1 50 M = N + N*N 60 L = LEN(STR$(M)) 70 IF L <> 8 THEN 150 80 REM We now work out the Dth digit from the right and the Dth digit from the left and see if they are the same 90 D = 0 91 REPEAT 92 D = D + 1 100 left$ = MID$(STR$(M), D, 1) 110 right$ = MID$(STR$(M), 9 - D, 1) 120 UNTIL D = 4 OR left$ <> right$ 130 REM if left$ = right$ when we get to this line then M = palindrome 140 IF left$ = right$ THEN PRINT N, M 150 UNTIL L > 8 155 PRINT "Time = ";(TIME - start%) / 100;"s" >RUN 5291 27999972 5313 28233282 Time = 322.32s >LikeLike
Jim Randell 3:40 pm on 5 March 2023 Permalink |
A little bit of analysis can significantly reduce the number of cases tested:
In order for n(n + 1) to be a palindrome it cannot be divisible by 10, so neither n nor (n + 1) can be divisible by 5 (as one of them will be even).
And if (n + 22)(n + 23) is a palindrome, neither (n + 22) nor (n + 23) can be divisible by 5.
So the residue of n mod 5 cannot be 0, 2, 3, 4. Hence it must be 1.
So we only need to consider n values of the form (5k + 1).
Also if n(n + 1) is an 8-digit palindrome, say ABCDDCBA then we have:
So one of n, (n + 1) must be divisible by 11. (And also one of (n + 22), (n + 23) but that follows directly).
So here is a program that only considers 248 candidate numbers, and has an internal runtime of 491µs.
Run: [ @replit ]
from enigma import (irange, inf, is_npalindrome, nsplit, printf) # function to apply f = lambda x: x * (x + 1) # consider possible numbers for n in irange(1, inf, step=5): if n % 11 not in {0, 10}: continue # apply the function v = f(n) if v < 10_000_000: continue v2 = f(n + 22) if v2 > 100_000_000: break # is the result a palindrome? if is_npalindrome(v) and is_npalindrome(v2): printf("f({n}) = {v}; f({n2}) = {v2}", n2=n + 2)In particular using this approach I was able to write a modified version of Victor’s BBC BASIC program that reduced the runtime from 5m22s (Victor’s original program) to 13.9s (my modified program).
>LIST 10 REM Modification of Victor Bryant program for Teaser 1071 20 REM from "Microteasers" (1986) 30 REM We want N + N^2 to be an 8-digit palindrome 40 start% = TIME 50 FOR N = 3161 TO 9999 STEP 5 60 IF N MOD 11 <> 0 AND N MOD 11 <> 10 THEN 140 70 P = N + N*N 80 IF NOT FNpal(STR$(P)) THEN 140 90 M = N + 22 100 Q = M + M*M 110 IF NOT FNpal(STR$(Q)) THEN 140 120 PRINT N, P 130 PRINT M, Q 140 NEXT N 150 PRINT "Time = ";(TIME - start%) / 100;"s" 160 END 170 REM check for 8 character palindrome 180 DEF FNpal(M$) 190 IF LEN(M$) <> 8 THEN =FALSE 200 FOR D = 1 TO 4 210 left$ = MID$(M$, D, 1) 220 right$ = MID$(M$, 9 - D, 1) 230 IF left$ <> right$ THEN =FALSE 240 NEXT D 250 =TRUE >RUN 5291 27999972 5313 28233282 Time = 13.9sBut the setter must have some other analysis in mind to reduce the number of calculations to less than 20.
LikeLike
GeoffR 1:29 pm on 5 March 2023 Permalink |
# testing for (num + square(num)) between 10 million and 100 million approx. # LB = 3161 + 3161 ** 2 = 9,995,082 # UB = 9999 + 9999 ** 2 = 99,990,000 for n in range(3161, 10000): sum_prod = n + n ** 2 # check if this number is a numerical palindrome if str(sum_prod) == str(sum_prod)[::-1]: # Second number is 22 more than first number n2 = n + 22 sum_prod2 = n2 + n2 ** 2 # check if this number is a numerical palindrome if str(sum_prod2) == str(sum_prod2)[::-1]: print(f"Pair of numbers are {n} and {n2}.") print(f"Associated Palindromes are {sum_prod} and {sum_prod2}.") # Pair of numbers are 5291 and 5313. # Associated Palindromes are 27999972 and 28233282.LikeLike
GeoffR 8:57 am on 6 March 2023 Permalink |
LikeLike
John Crabtree 4:59 pm on 8 March 2023 Permalink |
f(N) = N(N+1) = “ABCDDCBA” = 0 (mod 11) as the sum of alternating digits is the same
f(N+22) – f(N) = 44N + 506
The first and last digits do not change. The second digit from the left, B, must either be the same or increase by 1.
If it stays the same, 44N + 506 = 0 (mod 100) with no solution.
If it increases by 1, 44N + 506 = 10 (mod 100) which leads to N = 16 mod 25
41*42 = 66*67 = 22 (mod 100)
sqrt(22) = 4.690 and sqrt(23) = 4.795
4741 = 0 (mod 11), but f(4741+22) must start with 22 and is invalid
4766 = 3 (mod 11)
16*17 = 91*92 = 72 (mod 100)
sqrt(27) = 5.196 and sqrt(28) = 5.291
5191 = 10 (mod 11), but is too small
5216 = 2 (mod 11)
5291 = 0 mod 11, and f(5191+22) must start with 28
And so the numbers must be 5291 and 5313.
At this point the calculator is very useful to find that
f(5291) = 27,999,922 and f(5313) = 28,233,282
There are not many calculations in this solution. I do not understand the setter’s statement about needing as many calculations again to show that the solution is unique. That is included above.
LikeLike
John Crabtree 5:50 am on 10 March 2023 Permalink |
Simplifying, N = -34 + 275k = 10 (mod 11); or N = 66 + 275k = 0 (mod 11)
With AB = 22 or 27, there are only two possible values of N:
4741 = 4675 (17 * 275) + 66, but f(4741 + 22) is invalid
5291 = 5225 (19 * 275) + 66, and f(5291 + 22) = f(5313) is valid
LikeLike