Teaser 3302: Challenging grandson
From The Sunday Times, 4th January 2026 [link] [link]
My grandson likes making puzzles; his most recent one started with a four-digit number with all the digits different. He added up all the possible two-digit combinations of these four digits (e.g., if the digits were 0, 1, 2 and 3 he would add 01 + 02 + 03 + 10 + 12 + …). This total divided exactly into his four-digit number.
Not satisfied with this, he said he had added an extra digit (different from all the others) to the end of his number to make a five-digit number. The five-digit number was an exact multiple of the total of all the two-digit combinations of these five digits. He said that if he told me how many digits were in this multiple, I would be able to work out his five-digit number.
What was his five-digit number?
[teaser3302]















Jim Randell 7:35 am on 4 January 2026 Permalink |
When constructing the sum of the combinations, with 4 digits, each can be paired with 3 others, and so appears 3 times in the tens column and 3 times in the units column. The total sum is therefore:
And starting with 5 digits the total sum is:
This Python program runs in 68ms. (Internal runtime is 955µs).
from enigma import (irange, nsplit, div, ulambda, filter_unique, ndigits, printf) # generate possible scenarios def generate(): digits = set(irange(0, 9)) # the first number is a 4-digit multiple of 33 with distinct digits for n1 in irange.round(1000, 9999, step=33, rnd='I'): ds = nsplit(n1) if len(set(ds)) != 4: continue # calculate the sum of the 2-digit combinations t1 = sum(ds) s1 = 33 * t1 # n1 is a multiple of s1 k1 = div(n1, s1) if k1 is None: continue # add in an extra digit to form the second number for d in digits.difference(ds): n2 = 10*n1 + d # calculate the sum of the 2-digit combinations s2 = 44 * (t1 + d) # n2 is a multiple of s2 k2 = div(n2, s2) if k2 is None: continue # return (number, sum, multiple) values for each number printf("[n1={n1} s1={s1} k1={k1} -> n2={n2} s2={s2} k2={k2}]") yield ((n1, s1, k1), (n2, s2, k2)) # find solutions unique by number of digits in k2 f = ulambda("((n1, s1, k1), (n2, s2, k2)): ndigits(k2)") ss = filter_unique(generate(), f).unique # output solutions for ((n1, s1, k1), (n2, s2, k2)) in ss: printf("n2={n2} [s2={s2} k2={k2}; n1={n1} s1={s1} k1={k1}]")Solution: [To Be Revealed]
LikeLike
Ruud 8:51 am on 4 January 2026 Permalink |
import peek import istr import collections collect = collections.defaultdict(list) for n4 in istr.range(1000, 10000): if not n4.all_distinct(): continue s4 = 33 * sum(n4) if not n4.is_divisible_by(s4): continue for n1 in istr.range(10): if n1 in n4: continue n5 = n4 | n1 s5 = 44 * sum(n5) if n5.is_divisible_by(s5): multiple = n5 / s5 collect[len(multiple)].append(n5) for n5s in collect.values(): if len(n5s) == 1: peek(n5s[0]).
LikeLike
ruudvanderham 7:15 pm on 4 January 2026 Permalink |
Slightly faster:
import peek import istr import collections collect = collections.defaultdict(list) for p4 in istr.permutations(range(10), 4): n4 = istr.join(p4) s4 = 33 * sum(n4) if not n4.is_divisible_by(s4): continue for n1 in set(istr.range(10)) - set(p4): n5 = n4 | n1 s5 = 44 * sum(n5) if n5.is_divisible_by(s5): multiple = n5 / s5 collect[len(multiple)].append(n5) for n5s in collect.values(): if len(n5s) == 1: peek(n5s[0])LikeLike
Frits 11:43 am on 4 January 2026 Permalink |
from itertools import permutations # the extra digit must be zero due to the alternating sum rule d = dict() for A, B, C in permutations(range(1, 10), 3): # divisibility of 11 rule (alternating digit sum is 0 or a multiple of 11) if (D := (A + C - B) % 11) in {0, A, B, C, 10}: continue # calculate sum of digits (must be a multiple of 3) if (s := A + B + C + D) % 3: continue # calculate first multiple m1, r = divmod(ABCD := 1000 * A + 100 * B + 10 * C + D, 33 * s) if r or m1 % 2: continue # as m2 = 7.5 * m1 # number of digits in second multiple must be unique d[nd2] = 0 if (nd2 := len(str(m2 := int(7.5 * m1)))) in d else 10 * ABCD for k, v in d.items(): if v: print("answer:", v)LikeLike
Frits 12:47 pm on 4 January 2026 Permalink |
from itertools import permutations # the extra digit must be zero due to the alternating sum rule d = dict() digits = set(range(1, 10)) # D must be even as 10 * ABCD must be divisible by 44 for D in [2, 4, 6, 8]: for A, C in permutations(digits - {D}, 2): # divisibility of 11 rule (alternating digit sum is 0 or a multiple of 11) if (B := (A + C - D) % 11) in {0, A, C, D, 10}: continue # calculate sum of digits (must be a multiple of 3) if (s := A + B + C + D) % 3: continue # calculate first multiple m1, r = divmod(ABCD := 1000 * A + 100 * B + 10 * C + D, 33 * s) if r or m1 % 2: continue # as m2 = 7.5 * m1 # number of digits in second multiple must be unique d[nd2] = 0 if (nd2 := len(str(int(7.5 * m1)))) in d else 10 * ABCD for k, v in d.items(): if v: print("answer:", v)LikeLike