Teaser 2652: Square meals
From The Sunday Times, 21st July 2013 [link] [link]
A company produces five different types of muesli. The ingredients are bought from a wholesaler who numbers his items from 1 to 10. In each type of muesli there is a mixture of a square number of different ingredients and the weight in grams of each ingredient is the square of its item number: also the total weight of its ingredients is a perfect square number of grams.
Last month one of the ingredients was unavailable and so only the “basic” and “fruity” varieties could be produced. This week a different ingredient is unavailable and so only the “luxury” variety can be made.
What are the item numbers of the ingredients in the luxury muesli?
[teaser2652]







Jim Randell 7:55 am on 14 November 2023 Permalink |
I assumed each mixture has multiple ingredients, and as there are only 10 possible ingredients this means each must have 4 or 9.
This Python program looks for sets of 4 or 9 numbers from 1 to 10 whose squares sum to a square number. We then choose 5 of these sets to form the different types of muesli made, and look for the 2 (different) unavailable ingredients. The first unavailable ingredient only allows 2 of the types to be made (these are “basic” and “fruity”) and the second only allows 1 to be made (and this is “luxury”).
It runs in 84ms. (Internal runtime is 879µs).
Run: [ @replit ]
from enigma import (irange, subsets, sq, is_square, union, intersect, printf) # collect possible collections of ingredients ms = list() # choose 4 or 9 ingredients for k in [4, 9]: for ns in subsets(irange(1, 10), size=k): # calculate the total weight t = sum(sq(n) for n in ns) if not is_square(t): continue printf("[k={k}: ns={ns} t={t}]") ms.append(ns) # choose 5 varieties for vs in subsets(ms, size=5): ns = union(vs) # choose the first unavailable ingredient for u1 in ns: # find how many can be made without u1 vs1 = list(v for v in vs if u1 not in v) # there are 2 that cannot be made ("basic" and "fruity") if len(vs1) != 2: continue # choose the second unavailable ingredient for u2 in ns: if u2 == u1: continue # find how many can be made without u2 vs2 = list(v for v in vs if u2 not in v) # there is only 1 that cannot be made ("luxury") if len(vs2) != 1: continue if intersect([vs1, vs2]): continue # output solution printf("u1={u1} -> basic/fruity={vs1}; u2={u2} -> luxury={vs2[0]}")Solution: Luxury muesli uses ingredients: 2, 4, 5, 6.
There are only 5 possible sets of ingredients, so these correspond to each of the 5 types of museli:
The unavailable ingredient last month was 4, meaning only: (1, 2, 8, 10) and (5, 6, 8, 10) could be made. These are (in some order) “basic” and “fruity”.
The unavailable ingredient this week is 10, meaning only (2, 4, 5, 6) can be made, and this is “luxury”.
LikeLike