Teaser 3149: Cube route
From The Sunday Times, 29th January 2023 [link] [link]
I have a set of ten cards, each of which has a different digit written on it. All the cards have been used to make a set of prime numbers. After discarding the smallest prime, and without changing the order of any cards, I have placed the remaining primes in order of decreasing size to give a large number. It is possible, without changing the order of any cards, to break this number into a set composed entirely of cubes. Neither set contains a number with more than four digits.
List, in order of decreasing size, my set of prime numbers.
[teaser3149]
Jim Randell 4:31 pm on 27 January 2023 Permalink |
This Python program uses the [[
mcover()]] (exact multiset cover) routine from the enigma.py library, that I implemented for Enigma 1712 (and also used in Teaser 2690).It runs in 228ms.
Run: [ @replit ]
from enigma import ( primes, powers, inf, is_duplicate, group, item, multiset, mcover, trim, join, printf ) # select numbers (as strings) with up to <k> digits and no repeated digits def select(seq, k=4): for n in seq: s = str(n) if len(s) > k: break if is_duplicate(s): continue yield s # cubes and primes up to 4-digits (as strings) cbs = group(select(powers(0, inf, 3)), by=item(0)) # grouped by first digit prs = dict((s, multiset.from_seq(s)) for s in select(primes)) # mapped to digit content # chop string <t> into segments from <ss> def chop(t, ss, rs=[]): # are we done? if not t: yield rs else: for s in ss.get(t[0], []): if t.startswith(s): yield from chop(trim(t, head=len(s)), ss, rs + [s]) # find primes that cover each digit exactly once digits = multiset.from_seq("0123456789") for ps in mcover(prs, digits): # put them in order ps.sort(key=(lambda n: (len(n), n)), reverse=1) # make the large number, by discarding the smallest prime n = join(trim(ps, tail=1)) # chop the large number into cubes for ss in chop(n, cbs): printf("{ps} -> {n} -> {ss}", ps=join(ps, sep=":"), ss=join(ss, sep=":"))Solution: The primes were: 827, 409, 61, 53.
The initial set of primes found was (in decreasing order):
The smallest of these (53) is discarded, and the rest assembled into the following sequence:
This can then be split into cubes as follows:
A variation on the puzzle (with a different answer) is achieved by placing the primes in ascending order, removing the smallest, and then splitting the remaining sequence into cubes.
If the primes are arranged in increasing order we can start with:
Again, we discard the smallest prime (53), which leaves:
And this can be split into cubes as follows:
The same 4 cubes as the original puzzle, but in a different order.
LikeLike