Teaser 2507: [Favourite foods]
From The Sunday Times, 10th October 2010 [link] [link]
Six friends have the first names Bubba, Chris, Derek, Emiren, Finsan and Gilson. They each have a different favourite food — apple, carrot, pear, pinto bean, raspberry and watermelon.
No two friends have birthdays in the same month. For each friend, any two from their name, their favourite food and their month of birth have just one letter of the alphabet in common.
In the order of names given above, what are their favourite foods?
This puzzle was originally published with no title.
[teaser2507]
Jim Randell 8:41 am on 12 September 2025 Permalink |
This is another puzzle that can be solved directly with the [[
grouping]] solver from the enigma.py library.The following Python program runs in 66ms. (Internal runtime is 1.4ms).
Solution: The favourite foods are: watermelon, pear, pinto bean, carrot, apple, raspberry.
The complete solution is:
LikeLike
Frits 2:30 pm on 12 September 2025 Permalink |
names = ["Bubba", "Chris", "Derek", "Emiren", "Finsan", "Gilson"] ns = [x.lower() for x in names] foods = ["apple", "carrot", "pear", "pinto bean", "raspberry", "watermelon"] fs = [x.strip() for x in foods] months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ] ms = [x.lower() for x in months] # does sequence <x> share exactly one item with all sequences in <g> share1 = lambda x, g: all(len(set(x).intersection(z)) == 1 for z in g) # pick one value from each entry of a <k>-dimensional dictionary <dct> # so that all elements in the <k> values are different def pickOneFromEach(k, dct, seen=set(), ss=[]): if k == 0: yield ss else: for vs in dct[k - 1]: # values in vs may not have been used before if seen.isdisjoint(vs): yield from pickOneFromEach(k - 1, dct, seen | set(vs), ss + [vs]) # dictionary of food, month per name index d = {i: [(fo, mo) for fo in fs if share1(fo, [na]) for mo in ms if share1(mo, [na, fo])] for i, na in enumerate(ns)} for s in pickOneFromEach(len(names), d): for i, (f, m) in enumerate(s[::-1]): print(f"{names[i]}: {foods[fs.index(f)]}, {months[ms.index(m)]}") print()LikeLike