Teaser 3142: Mrs Hyde’s garden design tips
From The Sunday Times, 11th December 2022 [link] [link]
I’m planting four differently-coloured plots in a line. Mrs Hyde’s design principles classify eight colours into five categories. Adjacent plots mustn’t have the same category, or even certain pairs of categories.
“Every scheme you’ve suggested has at least one adjacent pair of categories that breaks my rules”, said Mrs Hyde. “White, Green, Yellow, White has Honest and Social adjacent; Blue, Orange, Pink, Violet has Ardent and Social adjacent; Green, Violet, Blue, Orange has Ardent and Honest adjacent; Violet, White, Orange, Red has Droll and Honest adjacent; and White, Violet, Green, Blue has Jolly and Social adjacent. However, if you change one colour in one of your suggestions then it will work”.
What are the four colours in order in the changed suggestion that would be allowable?
[teaser3142]




Jim Randell 4:55 pm on 9 December 2022 Permalink |
Here is my first attempt. It is not particularly quick, but I’ll have another look at this puzzle later.
The program maps the different colours to the categories and checks that each of the given arrangements provides (at least) the corresponding objection. One we have a viable map we change one of the colours in one of the given arrangements and look for new arrangements that do not give rise to any of the objections raised previously.
This Python program runs in 866ms.
Run: [ @replit ]
from enigma import (subsets, tuples, update, wrap, uniq, map2str, printf) # colours and categories cols = "BGOPRVWY" cats = "ADHJS" # invalid arrangements and objections inv = { 'WGYW': 'HS', 'BOPV': 'AS', 'GVBO': 'AH', 'VWOR': 'DH', 'WVGB': 'JS', } # banned adjacencies banned = set(frozenset([x]) for x in cats) banned.update(map(frozenset, inv.values())) # check each of the arrangements provides the required objection def check(m): # check each of the arrangements for (k, v) in inv.items(): adj = set(v) if not any({m[x], m[y]} == adj for (x, y) in tuples(k, 2)): return False # looks OK return True @wrap(uniq) # change one of the arrangements def change(ks): for k in ks: for (i, x) in enumerate(k): # make a changed arrangement for y in cols: if y != x: yield update(k, [(i, y)]) # map colours to categories for ss in subsets(cats, size=len(cols), select="M"): m = dict(zip(cols, ss)) # each category must be represented if not set(m.values()).issuperset(cats): continue # check the given arrangements are objectionable if not check(m): continue # find a changed arrangement that is not objectionable for s in change(inv.keys()): # look for banned adjacencies in the new arrangement if not any(frozenset([m[x], m[y]]) in banned for (x, y) in tuples(s, 2)): # output solution printf("{s} [{m}]", m=map2str(m, sep=" ", enc=""))Solution: The allowable arrangement is: White, Red, Green, Blue.
The colour assignments are:
And so the given arrangements (and their objections) are:
However, swapping Violet for Red in the final arrangement gives:
Which does not give any of the objections we have discovered so far.
LikeLike
Jim Randell 6:25 pm on 9 December 2022 Permalink |
Here is a much faster version of my program (and not much longer). It uses the [[
SubstitutedExpression()]] solver from the enigma.py library to assign the colours to the categories, such that the objections for each arrangement applies.It runs in 57ms. (Internal runtime is 5.6ms).
Run: [ @replit ]
from enigma import (SubstitutedExpression, wrap, uniq, update, tuples, map2str, printf) # colours and categories cols = "BGOPRVWY" cats = "ADHJS" # invalid arrangements and objections inv = { 'WGYW': 'HS', 'BOPV': 'AS', 'GVBO': 'AH', 'VWOR': 'DH', 'WVGB': 'JS', } # map categories to digits 1-5 d = dict(A=1, D=2, H=3, J=4, S=5) # construct an alphametic puzzle to assign categories to the colours p = SubstitutedExpression( [ # WGYW has H and S adjacent "{3, 5} in [{W, G}, {G, Y}, {Y, W}]", # BOPV has A and S adjacent "{1, 5} in [{B, O}, {O, P}, {P, V}]", # GVBO has A and H adjacent "{1, 3} in [{G, V}, {V, B}, {B, O}]", # VWOR has D and H adjacent "{2, 3} in [{V, W}, {W, O}, {O, R}]", # WVGB has J and S adjacent "{4, 5} in [{W, V}, {V, G}, {G, B}]", ], digits=(1, 2, 3, 4, 5), distinct=(), ) # set of banned adjacencies banned = set(frozenset([d[x]]) for x in cats) banned.update(frozenset([d[x], d[y]]) for (x, y) in inv.values()) @wrap(uniq) # change one of the arrangements def change(ks): for k in ks: for (i, x) in enumerate(k): # make a changed arrangement for y in cols: if y != x: yield update(k, [(i, y)]) # solve the alphametic puzzle to map colours to categories for m in p.solve(verbose=0): # find a changed arrangement that is not objectionable for s in change(inv.keys()): # look for banned adjacencies in the new arrangement if not any(frozenset([m[x], m[y]]) in banned for (x, y) in tuples(s, 2)): # output solution printf("{s} [{m}]", m=map2str(m, sep=" ", enc=""))LikeLike