Teaser 2718: By the dozen
From The Sunday Times, 26th October 2014 [link] [link]
I have written down a five-figure number that uses five different non-zero digits, and then I have replaced the digits by letters to give DOZEN. Within this it is possible to see various numbers, namely:
D, O, Z, E, N
DO, OZ, ZE, EN
DOZ, OZE, ZEN
DOZE, OZEN
DOZENSurprisingly, the original number is divisible by a dozen or more of these.
What is the number DOZEN?
[teaser2718]



Jim Randell 11:23 am on 31 January 2023 Permalink |
Of the 15 fragments, there can be at most 3 of them that do not divide into DOZEN, and we don’t need to check that DOZEN divides into itself, so we just need to check that at most 3 of the fragments of length 1 to 4 do not.
This Python program runs in 193ms. (Internal runtime is 92ms).
from enigma import (irange, tuples, nconcat, subsets, icount_at_most, printf) # construct fragments of sequence <seq>, of size <ks> def fragments(seq, ks): for k in ks: for t in tuples(seq, k): yield t # consider 5 different digits for ds in subsets(irange(1, 9), size=5, select="P"): n = nconcat(ds) # fragments of length 1-4 fs = fragments(ds, irange(1, 4)) # at most 3 of the fragments do not divide into n fn = lambda ds: n % nconcat(ds) != 0 if icount_at_most(fs, fn, 3): # output solution printf("DOZEN = {n}")Solution: DOZEN = 31248.
There are 3 fragments that do not divide 31248. These are: 312, 3124, 1248.
And the remaining 12 fragments do divide 31248.
LikeLike
GeoffR 1:55 pm on 31 January 2023 Permalink |
As a contrast, I checked for eleven fragments which do divide the five digit number.
With the five digit number itself, this is equivalent to twelve divisions. I did not consider it necessary check for more than twelve divisions.
% A Solution in MiniZinc include "globals.mzn"; var 1..9:D; var 1..9:O; var 1..9:Z; var 1..9:E; var 1..9:N; constraint all_different([D, O, Z, E, N]); var 10..99:DO = 10*D + O; var 10..99:OZ = 10*O + Z; var 10..99:ZE = 10*Z + E; var 10..99:EN = 10*E + N; var 100..999:DOZ = 100*D + 10*O + Z; var 100..999:OZE = 100*O + 10*Z + E; var 100..999:ZEN = 100*Z + 10*E + N; var 1000..9999: DOZE = 1000*D + 100*O + 10*Z + E; var 1000..9000: OZEN = 1000*O + 100*Z + 10*E + N; var 10000..99999:DOZEN = 10000*D + 1000*O + 100*Z + 10*E + N; % % DOZEN divides itself, so only 11 fragment divisions to check constraint sum ([DOZEN mod D == 0, DOZEN mod O == 0, DOZEN mod Z == 0, DOZEN mod E == 0, DOZEN mod N == 0, DOZEN mod DO == 0, DOZEN mod OZ == 0,DOZEN mod ZE == 0, DOZEN mod EN == 0, DOZEN mod DOZ == 0,DOZEN mod OZE == 0,DOZEN mod ZEN == 0, DOZEN mod DOZE == 0, DOZEN mod OZEN == 0]) == 11; solve satisfy; output ["DOZEN = " ++ show(DOZEN) ]; % DOZEN = 31248 % ---------- % ==========LikeLike