Teaser 2596: Unusual factors
From The Sunday Times, 24th June 2012 [link] [link]
There are no neat tests for divisibility by 7 or 13, so it’s unusual for these factors to feature in Teasers. Today we put that right.
If you start with any three different non-zero digits, then you can make six different three-digit numbers using precisely those digits. For example, with 2, 5 and 7 you get 257, 275, 527, 572, 725 and 752. Here, one of their differences (572 − 257) is divisible by 7, and another (725
− 257) is divisible by 13.Your task today is to find three different digits so that none of the six possible three-digit numbers and none of the differences between any pair of them is a multiple of either 7 or 13.
What are the three digits?
My review of puzzles posted in 2024 is at Enigmatic Code: 2024 in review.
[teaser2596]




Jim Randell 4:44 pm on 31 December 2024 Permalink |
This Python program looks at possible sets of three digits, and then uses the [[
generate()]] function to generate possible arrangements and differences. This means as soon as we find a number that fails the divisibility tests we can move on to the next set of digits.It runs in 65ms. (Internal runtime is 491µs).
from enigma import (irange, subsets, nconcat, printf) # generate numbers to test from digits <ds> def generate(ds): seen = list() # consider all arrangements of the digits for n in subsets(ds, size=len, select='P', fn=nconcat): # return the arrangement yield n # return the differences for x in seen: yield abs(n - x) seen.append(n) # choose 3 digits for ds in subsets(irange(1, 9), size=3): # check numbers are not divisible by 7 or 13 if any(n % 7 == 0 or n % 13 == 0 for n in generate(ds)): continue # output solution printf("digits = {ds}")Solution: The three digits are: 1, 4, 9.
See also: A video by Matt Parker on divisibility tests [@youtube].
LikeLike
GeoffR 7:34 pm on 1 January 2025 Permalink |
from itertools import permutations from enigma import nsplit N = [] for a, b, c in permutations(range(1, 10), 3): n1, n2 = 100*a + 10*b + c, 100*a + 10*c + b n3, n4 = 100*b + 10*a + c, 100*b + 10*c + a n5, n6 = 100*c + 10*a + b, 100*c + 10*b + a # Check three-digit numbers are not divisible by 7 or 13 if any(x % 7 == 0 for x in (n1 ,n2, n3, n4, n5, n6)): continue if any(x % 13 == 0 for x in (n1, n2, n3, n4, n5, n6)): continue N.append(n1) # check differences for each number in the list # of potential candidates for m in N: x, y, z = nsplit(m) m1, m2 = m, 100*x + 10*z + y m3, m4 = 100*y + 10*x + z, 100*y + 10*z + x m5, m6 = 100*z + 10*x + y, 100*z + 10*y + x # a manual check of the 15 differences of each 6-digit number if abs(m1-m2) % 7 == 0 or abs(m1-m2) % 13 == 0: continue if abs(m1-m3) % 7 == 0 or abs(m1-m3) % 13 == 0: continue if abs(m1-m4) % 7 == 0 or abs(m1-m4) % 13 == 0: continue if abs(m1-m6) % 7 == 0 or abs(m1-m5) % 13 == 0: continue if abs(m1-m6) % 7 == 0 or abs(m1-m6) % 13 == 0: continue # if abs(m2-m3) % 7 == 0 or abs(m2-m3) % 13 == 0: continue if abs(m2-m4) % 7 == 0 or abs(m2-m4) % 13 == 0: continue if abs(m2-m5) % 7 == 0 or abs(m2-m5) % 13 == 0: continue if abs(m2-m6) % 7 == 0 or abs(m2-m6) % 13 == 0: continue # if abs(m3-m4) % 7 == 0 or abs(m3-m4) % 13 == 0: continue if abs(m3-m5) % 7 == 0 or abs(m3-m5) % 13 == 0: continue if abs(m3-m6) % 7 == 0 or abs(m3-m6) % 13 == 0: continue # if abs(m4-m5) % 7 == 0 or abs(m4-m5) % 13 == 0: continue if abs(m4-m6) % 7 == 0 or abs(m4-m6) % 13 == 0: continue if abs(m5-m6) % 7 == 0 or abs(m5-m6) % 13 == 0: continue if x < y < z: print(f"The three digit numbers are {x}, {y} and {z}.") # The three digit numbers are 1, 4 and 9.I resorted to a manual check of the differences of the 6 numbers arising from each 3 digit candidate, as it was not coming out easily in code.
LikeLike