From The Sunday Times, 16th November 1986 [link]
The artist Pussicato has a new painting which is a 6×6 array of squares and each square is red or blue or green.
(A) Label the horizontal rows of the painting U, V, W, X, Y, Z from top to bottom and the vertical columns 1, 2, 3, 4, 5, 6 from left to right. Then U1, U3, V5 are red; W2, Z2 are blue; and U2, V4, X2, X3, Y3, Y4 are green. Also V1 and W1 are the same colour, as are Y1 and Z1, and also X6 and Y6. Each row and each column contains two red squares, two blue and two green.
(B) I do apologise. The information in (A) gives you a painting which is wrong in every square.
(C) Use the information in (B), together with the following facts. Any two squares which are next to each other, horizontally or vertically, have different colours. There are more green squares than blue squares.
(D) Look, I am so sorry. The information in (C) gives you a painting which is wrong in every square.
(E) To be serious, the information in (B) and (D) is correct.
Give (in order) the colours of the squares in the top row of Pussicato’s painting.
[teaser1263]
Jim Randell 4:45 pm on 4 September 2025 Permalink |
Here is a solution using the [[
SubstitutedExpression]] solver from the enigma.py library.It runs in 129ms. (Internal runtime of the generated program is 1.5ms).
Solution: Ursula bought: 1 rubber; 6 pencils; 5 pens.
The full solution is:
LikeLike
Jim Randell 11:24 am on 5 September 2025 Permalink |
Here is a solution using the [[
choose()]] function from the enigma.py library.It runs in 70ms (with an internal runtime of 387µs).
from enigma import (Record, decompose, choose, icount_exactly as count, nl, printf) # look for combinations of 12 items with a cost of 400p vs = list() for (rb, pl, pn) in decompose(12, 3, increasing=0, sep=0, min_v=0): if 2 * rb + 3 * pl + 4 * pn == 40: vs.append(Record(rb=rb, pl=pl, pn=pn)) # selection functions (in order) for each girl fns = [ None, # S (lambda S, T: S.pl == T.rb), # T (lambda S, T, U: T.pn == U.pl), # U None, # V (lambda S, T, U, V, W: V.rb == W.pn), # W ] # find candidate solutions for (S, T, U, V, W) in choose(vs, fns): # "just one girl bought the same number of pens as T did pencils" if not count((S, T, U, V, W), (lambda x, t=T.pl: x.pn == t), 1): continue # output solution printf("S: {S}{s}T: {T}{s}U: {U}{s}V: {V}{s}W: {W}", s=nl) printf()LikeLike
Frits 6:36 pm on 4 September 2025 Permalink |
from itertools import product N, T = 12, 400 pa, pb, pc = 20, 30, 40 # each girl spent 400p and bought 12 items and # bought <a> rubbers, <b> pencils and <c> pens # quantity options for the girls sols = [(a, b, c) for a in range(min(N, T // pa) + 1) for b in range(min(N - a, (T - a * pa) // pb) + 1) if T - pa * a - pb * b == pc * (c := N - a - b)] # determine quantities for all girls for S, T, U, V, W in product(sols, repeat=5): # Sue bought the same number of pencils as Tina did rubbers if S[1] != T[0]: continue # Tina had as many pens as Ursula had pencils if T[2] != U[1]: continue # Viola had as many rubbers as Wendy had pens if V[0] != W[2]: continue # just one girl bought the same number of pens as T did pencils if [x[2] for x in (S, T, U, V, W)].count(T[1]) != 1: continue print("answer:", U)LikeLike
Ruud 7:43 am on 5 September 2025 Permalink |
import types combinations = [ types.SimpleNamespace(rubbers=rubbers, pencils=pencils, pens=pens) for rubbers in range(20) for pencils in range(14) for pens in range(11) if pens * 40 + pencils * 30 + rubbers * 20 == 400 and pens + pencils + rubbers == 12 ] for s in combinations: for t in combinations: if s.pencils == t.rubbers: for u in combinations: if t.pens == u.pencils: for v in combinations: for w in combinations: if v.rubbers == w.pens: if sum(girl.pens == t.pencils for girl in (s, t, u, v, w)) == 1: for name in "Sue Tina Ursula Viola Wendy".split(): print(f"{name:7} {locals()[name[0].lower()]}")LikeLike