Teaser 1882: Multiple solutions
From The Sunday Times, 11th October 1998 [link]
One of the neatest problems ever published appeared on this page as Brainteaser 1040, on July 4, 1982. It asked for a number consisting of one each of the digits 1 to 9, so that the first digit of the number was divisible by 1, the first two (taken as a two-digit integer) by 2, and so on to 9. The answer was: 381654729.
The reverse of this problem is to use one of each digit to form a number of which the last digit is divisible by 1, the last two (taken as a two-digit integer) by 2, and so on, to 9 or 10, according to whether we use the digits 1 to 9 or 0 to 9.
There are, sadly, many answers. If you examined the last three digits of all the answers, and regarded them as three-digit numbers, it would strike you that they all had a large (highest) common factor.
Curiously, only one multiple of that factor (consisting of three different digits) fails to occur as the last three digits of an answer.
Which number is it that fails to occur?
[teaser1882]
Jim Randell 9:31 am on 27 December 2022 Permalink |
See also: Teaser 1040, Teaser 3053.
This Python program uses the [[
SubstitutedExpression]] solver from the enigma.py library to find answers to the embedded puzzle. It then calculates the GCD of the answers, and looks for 3-digit multiples of this value that do not occur.It runs in 62ms.
Run: [ @replit ]
from enigma import (SubstitutedExpression, mgcd, irange, nsplit, printf) # suppose the number is: ABCDEFGHIJ p = SubstitutedExpression( [ "IJ % 2 = 0", "HIJ % 3 = 0", "GHIJ % 4 = 0", "FGHIJ % 5 = 0", "EFGHIJ % 6 = 0", "DEFGHIJ % 7 = 0", "CDEFGHIJ % 8 = 0", "BCDEFGHIJ % 9 = 0", "ABCDEFGHIJ % 10 = 0", # or: "0 = J" ], d2i=dict(), answer="HIJ", ) # solve the puzzle and accumulate the answers ns = set(p.answers(verbose=0)) # calculate the gcd of the answers g = mgcd(*ns) # look for 3-digit multiples of g for m in irange.round(100, 999, step=g, rnd='I'): # does not occur in an answer if m in ns: continue # has 3 different digits if len(set(nsplit(m, 3))) != 3: continue # output solution printf("multiple = {m} [gcd = {g}]")Solution: The 3-digit multiple that does not occur is: 960.
There are 202 answers to the embedded puzzle. And the final 3 digits of each answer form a multiple of 120.
LikeLike
GeoffR 9:41 am on 28 December 2022 Permalink |
This program finds the maximum number of solutions and sets of digits for HIJ values.
From the output values in the HIJ set, it can be readily seen that the gcd is 120 and the missing multiples of this gcd are 600 and 960. 600 can be ruled out as a solution as it contains repeating digits, so the missing gcd multiple is 960 (8 x 120).
from functools import reduce # convert digit sequence to number d2n = lambda s: reduce(lambda x, y: 10 * x + y, s) J = 0 # 10th last digit cnt = 0 # counter for number of solutions dig3 = set() # set for all different values of HIJ for I in range(1, 10): IJ = d2n([I, J]) if IJ % 2 != 0:continue for H in range(1, 10): if H in (I, J): continue HIJ = d2n([H, I, J]) if HIJ % 3 != 0: continue for G in range(1, 10): GHIJ = d2n([G, H, I, J]) if G in (H, I, J): continue if GHIJ % 4 != 0:continue for F in range(1, 10): if F in (G, H, I, J): continue FGHIJ = d2n([F, G, H, I, J]) if FGHIJ % 5 != 0: continue for E in range(1, 10): if E in (F, G, H, I, J):continue EFGHIJ = d2n([E, F, G, H, I, J]) if EFGHIJ % 6 != 0:continue for D in range(1, 10): if D in (E, F, G, H, I, J):continue DEFGHIJ = d2n([D, E, F, G, H, I, J]) if DEFGHIJ % 7 != 0:continue for C in range(1, 10): if C in (D, E, F, G, H, I, J):continue CDEFGHIJ = d2n([C, D, E, F, G, H, I, J]) if CDEFGHIJ % 8 != 0: continue for B in range(1, 10): if B in (C, D, E, F, G, H, I, J):continue BCDEFGHIJ = d2n([B, C, D, E, F, G, H, I, J]) if BCDEFGHIJ % 9 != 0:continue for A in range(1, 10): if A in (B, C, D, E, F, G, H, I, J):continue ABCDEFGHIJ = d2n([A, B, C, D, E, F, G, H, I, J]) if ABCDEFGHIJ % 10 != 0:continue # update HIJ digit set and number of solutions dig3.add(HIJ) cnt += 1 print('Number of solutions = ', cnt) print('HIJ set = ', dig3) # Number of solutions = 202 # HIJ set = {480, 840, 360, 240, 720, 120}LikeLike