Teaser 2668: Small cubes
From The Sunday Times, 10th November 2013 [link] [link]
Oliver and Megan each had a different- sized cuboid whose sides were all whole numbers of centimetres in length. Their cuboids were painted all over. They each cut their cuboid into one-centimetre cubes, some of which were unpainted, the rest being painted on one or more face. Oliver observed that for both cuboids, the number of cubes with no painted faces was the same as the number with two painted faces. Then Megan added: “I have more cubes than you, and the difference between our totals is equal to the number of your unpainted cubes”.
How many of Megan’s cubes had just one painted face?
[teaser2668]
Jim Randell 12:37 pm on 7 January 2024 Permalink |
Consider a cubiod with dimensions a × b × c. Then we can calculate the number of cubelets that are painted on the required number of faces:
providing the smallest dimension is greater than 1.
And as some of the cubelets are unpainted the cuboids we are interested in must have smallest dimension of at least 3.
This Python program runs in 56ms. (Internal runtime is 335µs).
Run: [ @replit ]
from enigma import (defaultdict, irange, inf, decompose, map2str, printf) # total number of faces is indicated by key 7 total = 7 # for a cuboid of dimensions a x b x c # return number of cubelets by faces painted, and the total number of cubelets def cubelets(a, b, c): assert min(a, b, c) > 1 r = dict() r[3] = 8 r[2] = 4 * (a + b + c - 6) r[0] = (a - 2) * (b - 2) * (c - 2) t = a * b * c r[1] = t - sum(r.values()) r[total] = t return r def solve(): # collect cubes by total g = defaultdict(list) # consider increasing a + b + c dimensions for s in irange(3, inf): # consider cuboids for M for (a, b, c) in decompose(s, 3, increasing=-1, sep=0, min_v=3): # calculate number of cubelets r = cubelets(a, b, c) # we are interested in those cubes where r[0] = r[2] if not (r[2] == r[0] > 0): continue # consider smaller totals (for O) for (k, vs) in g.items(): # difference between totals d = r[total] - k if d < 1: continue for (r_, (a_, b_, c_)) in vs: if r_[0] == d: # return (M, O) as (cubelets, dimensions) yield ((r, (a, b, c)), (r_, (a_, b_, c_))) # record this cuboid g[r[total]].append((r, (a, b, c))) # find possible (M, O) values for ((r, (a, b, c)), (r_, (a_, b_, c_))) in solve(): fmt = lambda r: map2str(r, arr='->', enc="") printf("M = {a} x {b} x {c} [{r}]; O = {a_} x {b_} x {c_} [{r_}]", r=fmt(r), r_=fmt(r_)) break # only need the first answerSolution: Megan has 112 cubelets painted on just one face.
Megan has a cuboid with dimensions: 12 × 5 × 4.
Oliver has a cuboid with dimensions: 8 × 6 × 4.
And:
If cuboids with a dimensions less than 3 were allowed, then we can find further solutions using cuboids that give 0 unpainted cubelets, such as:
LikeLike