Teaser 2838: King Lear IV
From The Sunday Times, 12th February 2017 [link] [link]
King Lear IV’s realm consisted of a regular hexagon divided into 24 counties that were equal-sized equilateral triangles. In his will he wanted to share the counties among his six daughters, each daughter’s portion having the property that, if you walked in a straight line between any two points in it, then you remained in her portion. If two daughters’ portions had the same area then they had to be of different shapes (and not the mirror image of each other). He wanted Cordelia to have a single county (his favourite county on the edge of the kingdom), he wanted Goneril to have a hexagonal-shaped portion, and he knew the number of counties he wanted to allocate to each of the other daughters, with Reagan’s portion being the largest of all. It turned out that his requirements uniquely determined Goneril’s and Reagan’s counties.
What, in increasing order, were the numbers of counties allocated to the six daughters?
[teaser2838]
Jim Randell 9:10 am on 16 November 2021 Permalink |
I originally solved this puzzle using the Polyform Puzzler framework [link], the problem then becomes how to interface to framework, but it allowed me to quickly produce a solution using a variation on the code I had previously written for Enigma 321.
But having subsequently packaged my polyominoes code written for Enigma 321 into a separate module, I thought I could do the same for polyiamonds.
So I wrote a package polyiamonds.py [@github] that knows enough about the convex shapes that fit into the 24-hex grid, and used that to solve this puzzle.
Here is a reference for polyiamonds [link]. I used the same names, but added octiamonds “d8” (= “diamond”) and “t8” (= “trapezium”) to produce a complete set of convex polyiamonds that will fit in the required hexagonal grid. In total there are 12 possible shapes.
The program looks for 4 additional pieces to go with “T1” and “O6” (which we are told are there), and one of these pieces must be larger than “O6”. The position of the “T1” piece is fixed along the edge of grid. The program then looks for packings where the positions of Regan’s (the largest piece) and Goneril’s piece (“O6”) are uniquely determined. It runs in 67ms.
Run: [ @replit ]
from enigma import (defaultdict, subsets, diff, union, irange, ordered, join, printf) import polyiamonds # convex polyiamonds up to size 8 that fit in the hexagon pieces = { "T1": 1, "D2": 2, "I3": 3, "T4": 4, "I4": 4, "I5": 5, "O6": 6, "I6": 6, "I7": 7, "D7": 7, "d8": 8, "t8": 8, } # collect the shapes shapes = polyiamonds.shapes(pieces.keys()) # make the hexagonal grid grid = union(set((x, y) for y in irange(y1, y2)) for (x, y1, y2) in [(0, 3, 7), (1, 1, 7), (2, 0, 6), (3, 0, 4)]) # remove (1, 1) for T1 grid.remove((1, 1)) # accumulate results by the position of G (= O6) and R (= largest) def key(g, ps): cells = lambda g, k: ordered(*(c for (c, n) in g.items() if n == k)) return (cells(g, ps.index("O6") + 1), cells(g, len(ps))) # choose 4 pieces to go with T1 and O6 r = defaultdict(set) for ps in subsets(diff(pieces.keys(), ["T1", "O6"]), size=4, fn=list): # check the size ss = list(pieces[p] for p in ps) m = max(ss) if not (m > 6 and sum(ss) == 17 and ss.count(m) == 1): continue # attempt to fit the shapes into the grid ps.extend(["T1", "O6"]) ps = sorted(ps, key=lambda p: pieces[p]) ks = tuple(pieces[p] for p in ps) printf("{ps} -> {ks}\n", ps=join(ps, sep=" ", enc="[]"), ks=join(ks, sep=" ", enc="()")) n = 0 for g in polyiamonds.fit(list(shapes[p] for p in ps if p != "T1"), grid, start=2): r[ks].add(key(g, ps)) g[(1, 1)] = 1 # place T1 as 1 polyiamonds.output_grid(g) n += 1 printf("[{n} ways]\n") # look for a unique solution for (k, vs) in r.items(): if len(vs) == 1: printf("solution = {k}")Solution: The numbers of counties allocated to the daughters are: 1, 2, 4, 4, 6, 7.
I found three allocations that allow the grid to be packed. They are summarised in the following diagram:
(Click to enlarge).
The allocation that has only one way to pack the grid gives the solution.
LikeLike