Enigmatic Code

Programming Enigma Puzzles

Tantalizer 449: Gnomes and gardens

From New Scientist #1000, 13th May 1976 [link]

Loose Chippings horticultural club used to be an all-male preserve. But last year a row about whether there should be a prize competition for garden gnomes at the annual show led mysteriously to ladies being allowed to compete in all events. This lapse turned out disastrously, since the Misses Mulch then carried off all the prizes in all the events.

Each sister in fact won exactly two prizes, being the only person to gain prizes in both her successful events and having just one sister who got prizes in neither. Scoring was the usual 3 for 1st prize, 2 for 2nd and 1 for 3rd. Clara (a prize for veg. and the other for cut flowers) tied with Mildred (a prize for fruit and a better prize for shrubs). There were no other ties or any shared prizes and no sister won two prizes in the same event.

Precisely which prizes did Clara and Mildred win? And was there a prize competition for gnomes?


One response to “Tantalizer 449: Gnomes and gardens

  1. Jim Randell 11 July 2018 at 8:18 am

    Each sister won two events, and scored 1, 2 or 3 points in each event. Giving possible total scores of: 2, 3, 4, 5, 6. And only only two of the sisters achieved the same total. So there can be no more than 6 sisters. And each sister won exactly 2 prizes, so there can be no more than 12 prizes in all.

    But each event has three prizes, and we a given the names of 4 of the events, so there must be at least 12 prizes awarded.

    So there must be exactly the 4 events we are given (so there is no event for gnomes), and there must be 6 sisters.

    There are 24 points to be awarded in total, so the total of 4 must have been achieved by Clara and Mildred.

    The only two ways to achieve a total of 4 points are 1+3 or 2+2.

    Mildred did better in shrubs than in fruit, so must have scored 3 (1st place) for shrubs and 1 (3rd place) for fruit.

    The only way to achieve a total of 2 points is 1+1; 3 points = 1+2; Mildred’s 4 point total is 1+3, so all four 3rd places are used up, so Clara’s 4 point total must be 2+2 (so Clara got 2nd place in veg and 2nd place in flowers); 5 points = 2+3; 6 points = 3+3. This uses up each score 4 times.

    Solution: Clara got 2nd place in veg and 2nd place in flowers. Mildred got 1st place in shrubs, and 3rd place in fruit. There was no event for gnomes.

    The following diagram shows a possible assignment of points to the sisters in each of the events:

    For each pair of events there is exactly won sister that won prizes in both events, and one sister who won prizes in none:

    Fl & Fr: both = X, none = Y
    Fl & Sh: both = Z, none = W
    Fl & Ve: both = Clara, none = Mildred
    Fr & Sh: both = Mildred, none = Clara
    Fr & Ve: both = W, none = Z
    Sh & Ve: both = Y, none = X

    Once we have the scores for Clara and Mildred there are 6 ways to complete the table.

    Here’s a MiniZinc model that uses the fact that there are 4 events and 6 sisters to fill out the table:

    %#! mzn-gecode -a
    include "globals.mzn";
    % label the events
    set of int: Events = 1..4;
    int: Fl = 1;
    int: Fr = 2;
    int: Sh = 3;
    int: Ve = 4;
    % label the sisters
    set of int: Sisters = 1..6;
    int: C = 1;
    int: M = 2;
    int: W = 3;
    int: X = 4;
    int: Y = 5;
    int: Z = 6;
    % the table
    array [Sisters, Events] of var 0..3: points;
    % each event has 3, 2, 1 points awarded exactly once
    constraint forall (e in Events, p in 1..3) ((sum (s in Sisters) (points[s, e] = p)) = 1);
    % puzzle constraints:
    % each sister won exactly two prizes
    constraint forall (s in Sisters) ((sum (e in Events) (points[s, e] > 0)) = 2);
    % each pair of events has exactly one sister win prizes in both and exactly one sister win prizes in neither
    constraint forall (e1, e2 in Events where e1 < e2) ((sum (s in Sisters) (points[s, e1] > 0 /\ points[s, e2] > 0)) = 1);
    constraint forall (e1, e2 in Events where e1 < e2) ((sum (s in Sisters) (points[s, e1] = 0 /\ points[s, e2] = 0)) = 1);
    % Clara got a prize for Veg and another for Flowers
    constraint points[C, Ve] > 0 /\ points[C, Fl] > 0;
    % Mildred got a prize for Fruit and a better prize for Shrubs
    constraint points[M, Fr] > 0 /\ points[M, Sh] > points[M, Fr];
    % total points for a sister
    function var int: total(int: s) = (sum (e in Events) (points[s, e]));
    % Clara and Mildred tied on points
    constraint total(C) = total(M);
    % but there were no other ties, so let's assume the order is W > X > Y > Z
    constraint all_different([total(W), total(X), total(Y), total(Z), total(C)]);
    constraint decreasing([total(W), total(X), total(Y), total(Z)]);
    solve satisfy;

    And here’s a Python program that uses the minizinc.py wrapper library to format the output:

    from enigma import printf
    from minizinc import MiniZinc
    m = MiniZinc("tantalizer449.mzn", use_shebang=1)
    for s in m.solve():
      points = s['points']
      printf("   [Fl Fr Sh V] Total")
      for s in sorted(points.keys()):
        v = points[s]
        printf("{s}: {v} {t}", s='?CMWXYZ'[s], v=list(v[k] for k in sorted(v.keys())), t=sum(v.values()))

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: