Brainteaser 1047: Youth opportunities
From The Sunday Times, 22nd August 1982 [link]
Five of the shops in our local High Street sell cakes, electrical goods, greengrocery, hardware and shoes. Each decided recently take on two young assistants, one of each sex, from the Youth Opportunities Scheme.
These ten lucky youngsters include Hazel and Stephen, who live on either side of my house, and Eric from across the road. He gave me the following information:
The initials of the assistants’ forenames are all different from the initial of the shop in which they work. Moreover no boy works with a girl whose initial is the same as his own. In addition, Emma does not work with Henry, nor does she work in the shoe shop.
Henry doesn’t work the in the cake shop, Gordon is not in the hardware shop, Gwen is not in the shoe shop, and neither Charles nor Sheila work in the greengrocer’s.
If Carol works in the hardware shop, who sells the electrical goods?
This puzzle is included in the book The Sunday Times Book of Brainteasers (1994).
[teaser1047]










Jim Randell 6:51 pm on 4 September 2024 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.Most of the conditions can be dealt with using the [[
--distinct]] and [[--invalid]] parameters.The following run file executes in 70ms. (Internal runtime of the generated code is just 27µs).
Run: [ @jdoodle ]
We can write additional Python code to format the output nicely:
from enigma import (SubstitutedExpression, printf) # label shops and people shops = "Cakes Electricals Greengrocers Hardware Shoes".split() boys = "Charles Eric Gordon Henry Steven".split() girls = "Carol Emma Gwen Hazel Shiela".split() # load the puzzle p = SubstitutedExpression.from_file("teaser1047.run") # solve the puzzle, and format solutions for (bs, gs) in p.answers(verbose=0): for (s, (b, g)) in enumerate(zip(bs, gs)): printf("{s} = {b} + {g}", s=shops[s], b=boys[b], g=girls[g]) printf()Solution: Henry and Gwen work in the electrical goods shop.
The full solution is:
LikeLike
Frits 10:35 am on 5 September 2024 Permalink |
This is much more intuitive to me:
and
from enigma import (SubstitutedExpression, printf) # label shops and people shops = "Cakes Electricals Greengrocers Hardware Shoes".split() boys = "Charles Eric Gordon Henry Steven".split() girls = "Carol Emma Gwen Hazel Sheila".split() # load the puzzle p = SubstitutedExpression.from_file("teaser/teaser1047.run") # solve the puzzle, and format solutions for (bs, gs) in p.answers(verbose=0): for i in range(5): b, g = boys[bs.index(i)], girls[gs.index(i)] print(shops[i], "=", b, "+", g)LikeLike