Tagged: by: J L Bowles Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 11:18 am on 1 October 2024 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 545: Gold Cup 

    From The Sunday Times, 5th December 1971 [link]

    Although 42 horses (numbered 1 to 42) were originally entered for the Teaser Gold Cup, only 38 took part in the race.

    The number of the horse which came second in the race exceeded the number of the winner by the same number as that by which the number of the third horse exceeded the number of the second.

    When the numbers of the 4 non-runners were placed in numerical order, the difference between each number and the next was the same in every case, and that difference was the same as the difference between the number of the horse which won the race and the number of the horse which came second.

    The sum of the numbers of the highest and lowest of the four non-runners was equal to the sum of the numbers of the horses which came first, second, and third.

    One of the first three horses was numbered 15. Horses numbered 24 and 28 fell at the third fence, and were not remounted.

    What were the numbers of the 4 non-runners?

    [teaser545]

     
    • Jim Randell's avatar

      Jim Randell 11:18 am on 1 October 2024 Permalink | Reply

      Here is a solution using the [[ SubstitutedExpression ]] solver from the enigma.py library.

      It runs in 90ms. (Internal runtime of the generated program is 12ms).

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      # suppose the first three horses are: A, B, C (ordered by number)
      # and the four non-runners are: W, X, Y, Z (ordered by number)
      
      --base=43
      --digits="1-42"
      --distinct="ABCWXYZ"
      --invalid="24|28,ABCWXYZ"
      
      # A, B, C are ordered by number
      "A < B" "B < C"
      # and form an arithmetic progression (common diff = D)
      "B - A = D"
      "C - B = D"
      # one of them is 15
      "15 in {A, B, C}"
      
      # W, X, Y, Z are ordered by number
      "W < X" "X < Y" "Y < Z"
      # and form an arithmetic progression (common diff = D)
      "X - W = D"
      "Y - X = D"
      "Z - Y = D"
      
      # equal sums
      "W + Z == A + B + C"
      
      --template=""
      

      Solution: The 4 non-runners were: 12, 19, 26, 33.

      Which forms an arithmetic progression with common difference of 7.

      The horses in the first 3 places were: 8, 15, 22.

      Which also form an arithmetic progression with a common difference of 7.

      The sum of the numbers of the first 3 horses is 8 + 15 + 22 = 45, the same as the sum of the highest and lowest numbered non-runners 12 + 33 = 45.

      Like

      • Ruud's avatar

        Ruud 4:36 pm on 1 October 2024 Permalink | Reply

        import itertools
        
        
        for non_runners in itertools.combinations(set(range(1, 43)) - {15, 24, 28}, 4):
            if (diff := non_runners[1] - non_runners[0]) == non_runners[2] - non_runners[1] == non_runners[2] - non_runners[1] == non_runners[3] - non_runners[2]:
                runners123 = set(range(1, 43)) - set(non_runners) - {24, 28}
                for first in runners123:
                    second = first + diff
                    third = second + diff
                    if second in runners123 and third in runners123 and 15 in {first, second, third} and first + second + third == non_runners[0] + non_runners[3]:
                        print(f"{non_runners=} {first=} {second=} {third=}")
        

        , which prints:

        non_runners=(12, 19, 26, 33) first=8 second=15 third=22
        

        Like

    • GeoffR's avatar

      GeoffR 7:23 pm on 1 October 2024 Permalink | Reply

      
      
      % A Solution in MiniZinc
      include "globals.mzn";
      
      var 1..42:NR1; var 1..42:NR2; var 1..42:NR3; var 1..42:NR4;
      var 1..42:W1; var 1..42:W2; var 1..42:W3;
      
      constraint all_different ([NR1, NR2, NR3, NR4, W1, W2, W3]);
      
      constraint W2 - W1 == W3 - W2;
      
      constraint  NR1 < NR2 /\ NR2 < NR3 /\ NR3 < NR4;
      
      constraint NR2 - NR1 == NR3 - NR2 /\ NR3 - NR2 == NR4 - NR3;
      
      constraint NR2 - NR1 == W2 - W1;
      
      constraint NR1 + NR4 == W1 + W2 + W3;
      
      constraint sum ([W1 == 15, W2 == 15, W3 == 15]) == 1;
      
      var set of int: horses = {NR1, NR2, NR3, NR4, W1, W2, W3};
      
      constraint card ({24, 28} intersect horses) == 0;
      
      solve satisfy;
      
      output ["Numbers of non-runners = " ++ show([NR1, NR2, NR3, NR4]) ++
      "\nWinning numbers = " ++ show([W1, W2, W3]) ];
      
      % Numbers of non-runners = [12, 19, 26, 33]
      % Winning numbers = [8, 15, 22]
      % ----------
      % ==========
      
      
      

      Like

  • Unknown's avatar

    Jim Randell 12:12 pm on 14 May 2023 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 556: Air ways 

    From The Sunday Times, 27th February 1972 [link]

    Al, Bill, Cab, Don, Ed, Fred, Gil, Hal, and Ian were waiting at the airport. Three would take a plane going east, three plane going north and three a plane going south.

    Hal, but neither Ian nor Fred, was going south. Al would be travelling with Don or Cab. Fred would be travelling with Bill or Ed.

    Gil, unlike Ian, would be travelling east. Cab would take a seat next to Ed or Al. Ian would travel in a different plane from Bill, and in a different plane from Cab.

    If Don would still be waiting at the airport after Bill and Ed had left, who were the three going north?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser556]

     
    • Jim Randell's avatar

      Jim Randell 12:13 pm on 14 May 2023 Permalink | Reply

      We can use the [[ SubstitutedExpression ]] solver from the enigma.py library to solve this puzzle.

      The following run file executes in 65ms. (Internal runtime of the generated program is 285µs).

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      # allocate directions: 1=E, 2=N, 3=S
      --digits="1,2,3"
      --distinct=""
      
      # 3 go in each direction
      "multiset.from_seq([A, B, C, D, E, F, G, H, I]).all_same(3)"
      
      # H is going S; but I, F are not
      "H = 3" "I != 3" "F != 3"
      
      # A is travelling with D or C
      "A in {D, C}"
      
      # F is travelling with B or E
      "F in {B, E}"
      
      # G is travelling E; but I is not
      "G = 1" "I != 1"
      
      # C is travelling with E or A
      "C in {E, A}"
      
      # I is not travelling with B or C
      "I not in {B, C}"
      
      # D is not travelling with B or E
      "D not in {B, E}"
      
      --template=""
      

      Solution: Al, Don, Ian are travelling north.

      The full solution:

      East = B, F, G
      North = A, D, I
      South = C, E, H

      Like

      • Frits's avatar

        Frits 3:24 pm on 14 May 2023 Permalink | Reply

        Or:

        3 go in each direction

        “div(216, A * B * C * D * E * F * G * H) = I”

        Like

        • Jim Randell's avatar

          Jim Randell 3:40 pm on 14 May 2023 Permalink | Reply

          A good job I used non-zero digits ;-).

          Like

          • Frits's avatar

            Frits 5:19 pm on 14 May 2023 Permalink | Reply

            With zero you can use other non-zero digits d and 3d + 1 with check

            “(calculate 12d + 3) – sum([A, B, C, D, E, F, G, H]) = I”

            Like

  • Unknown's avatar

    Jim Randell 7:52 am on 7 June 2022 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 713: Better and better 

    From The Sunday Times, 16th March 1975 [link]

    When the four modest gamblers — Al, Bill, Carl and Don — sat down for their usual game of poker, each of the four placed on the table, as their stake money for the evening, a different whole number of pence.

    After a number of hands, Al found that he had exactly doubled the number of pence with which he had started. it was his turn to provide the evening’s refreshments, and he bought the first round of drinks. After a few more hands, Al exactly doubled the number of pence he had had left after buying the first round and he then bought a second round. Thereafter he repeated the process, i.e. he exactly doubled his remaining pence and bought a third round.

    During the fourth session, Al took every penny his three opponents still had on the table and found that he had exactly doubled the number of pence he had had left after buying the third round. He then bought a fourth round — which took every penny he himself had!

    Each of the four rounds of drinks cost precisely the same whole number of pence.

    Carl began the game with a number of pence (between 50 and 100) which was exactly half the total number of pence which Bill and Don had between them at the start.

    How many pence did Al have when the game began?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 2 (1981). The puzzle text above is taken from the book.

    [teaser713]

     
    • Jim Randell's avatar

      Jim Randell 7:55 am on 7 June 2022 Permalink | Reply

      If the starting amounts are (A, B, C, D). Then at the end of the first session A now has 2A and buys a round (costing R), so starts the second session with (2A − R).

      He ends the second session with twice his starting amount, i.e. (4A − 2R), and buys another round. So starts the third session with (4A − 3R).

      He ends the third session with twice his starting amount, i.e. (8A − 6R), and buys another round. So starts the fourth session with (8A − 7R).

      He ends the fourth session with twice his starting amount, i.e. (16A − 14R), and buys another round, leaving him with no money.

      Hence:

      16A − 15R = 0
      R = (16/15)A

      Also the purchasing of the 4 rounds used up all of the money:

      4R = A + B + C + D
      (4(16/15) − 1)A = B + C + D
      A = (15/49)(B + C + D)

      Now: C = (B + D) / 2, so:

      B + D = 2C
      A = (15/49)(3C)
      A = (45/49)C

      And:

      R = (16/15)A
      R = (48/49)C

      48 has no factors of 7, so C must have (at least) 2 factors of 7. And as C is in [50, 100] we must have:

      C = 98
      B + D = 196
      A = 90
      R = 96

      All that remains is to ensure B and D can be assigned values such that each of the four starts with a different stake.

      If we keep keep the stakes below 100p we can assign B and D to 97p and 99p (in some order). The four starting amounts are then (90p, 97p, 98p, 99p).

      Solution: Al started the game with 90p.

      So Al’s progress is:

      1: 90p → 180p; spends 96p
      2: 84p → 168p; spends 96p
      3: 72p → 144p; spends 96p
      4: 48p → 96p; spends 96p

      Like

  • Unknown's avatar

    Jim Randell 12:08 pm on 17 May 2022 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 703: Wheels of fortune 

    From The Sunday Times, 5th January 1975 [link]

    A small gaming machine has proved popular in East Bernia. Inside the machine three wheels spin independently on a common axle and on the “tread” of each wheel are three single-figured numbers. When a handle is pulled the wheels spin, and when they come to rest one number on each wheel is shown at the front of the machine.

    The nine numbers used are 1, 2, 3, 4, 5, 6, 7, 8 and 9. When added together, the three numbers on the first wheel total one less than the three on the second wheel, which total one less than the three on the third wheel.

    The method of scoring is to add the three “disclosed” numbers together, and the numbers are so placed on the wheels that it is possible to make any one of 17 different scores (16 of which are consecutive numbers). It is impossible to get the score of 7.

    What are the numbers on each wheel?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 2 (1981). The puzzle text above is taken from the book.

    [teaser703]

     
    • Jim Randell's avatar

      Jim Randell 12:09 pm on 17 May 2022 Permalink | Reply

      This Python program runs in 48ms. (Internal run time is 838µs).

      Run: [ @replit ]

      from enigma import (irange, div, partitions, cproduct, printf)
      
      # available digits
      digits = list(irange(1, 9))
      
      # calculate the required sums
      x = div(sum(digits), 3)
      ts = { x - 1, x, x + 1 }
      
      # does <ns> contains a <k>-length run of consecutive numbers
      # ns is a sorted sequence of distinct integers
      def is_consecutive(ns, k=2):
        k -= 1
        (i, j) = (0, k - len(ns))
        while j < 0:
          if ns[i] + k == ns[j] : return (i, j)
          i += 1
          j += 1
      
      # allocate the digits to the wheels
      for ws in partitions(digits, 3):
        if set(sum(w) for w in ws) != ts: continue
      
        # construct possible sums
        ss = set(sum(xs) for xs in cproduct(ws))
        if len(ss) != 17 or 7 in ss: continue
      
        # look for a consecutive run of 16
        ss = sorted(ss)
        if not is_consecutive(ss, 16): continue
      
        # output solution
        (w1, w2, w3) = sorted(ws, key=sum)
        printf("{w1} {w2} {w3} -> {ss}")
      

      Solution: The numbers on the wheels are: (3, 5, 6) (2, 4, 9) (1, 7, 8).

      The 17 scores that can be made are: 6 and 8 – 23.

      Like

    • Frits's avatar

      Frits 7:05 pm on 17 May 2022 Permalink | Reply

      Some easy deduction:

      As scores 6, 7, 23, and 24 can only be made with one combination we can conclude that 1, 2 and 3 must be on different wheels (same for 6, 8 and 9). So we know the scores 6 and 8 – 23.

      Also 3 and 4 cannot be on the same wheel as it leads to score 7.

      Like

  • Unknown's avatar

    Jim Randell 9:44 am on 12 April 2022 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 687: Fair deal 

    From The Sunday Times, 15th September 1974 [link]

    From a normal pack of playing cards, Bill, George, Harry and Joe were each dealt an Ace, a King, a Queen, a Jack and a ten.

    Harry’s five cards were in three different suits and consisted of three red and two black cards.

    Joe’s five cards were also in three different suits, his Ace being in the same suit as his Queen, and his King in the same suit as his Jack.

    George held more than one black card.

    Bill’s five cards were all in the same suit.

    Harry held the King of spades, and Joe the ten of diamonds.

    What were the cards in George’s hand?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 2 (1981). The puzzle text above is taken from the book.

    [teaser687]

     
    • Jim Randell's avatar

      Jim Randell 9:45 am on 12 April 2022 Permalink | Reply

      I used the [[ SubstitutedExpression ]] solver from the enigma.py library to fill out the suits of the cards.

      Here is the run file:

      #! python3 -m enigma -rr
      
      # assign values 0-3 (S=0; C=1; H=2; D=3) to:
      #
      #     A K Q J X
      #  B: a b c d e
      #  G: f g h i j
      #  H: k m n p q
      #  J: r s t u v
      
      SubstitutedExpression
      
      --base=4
      --distinct="afkr,bgms,chnt,dipu,ejqv"
      
      # red cards and black cards
      --code="red = lambda x: x > 1"
      --code="black = lambda x: x < 2"
      
      # H's cards were in 3 different suits
      "len({{k}, {m}, {n}, {p}, {q}}) == 3"
      # 3 red [and 2 black]
      "icount([{k}, {m}, {n}, {p}, {q}], red) == 3"
      
      # J's cards were in 3 different suits
      "len({{r}, {s}, {t}, {u}, {v}}) == 3"
      # suit of A is the same as Q
      "{r} = {t}"
      # suit of K is the same as J
      "{s} = {u}"
      
      # G has more than 1 black card
      "icount([{f}, {g}, {h}, {i}, {j}], black) > 1"
      
      # B's cards are in the same suit
      "{a} = {b}" "{b} = {c}" "{c} = {d}" "{d} = {e}"
      
      # H held KS (i.e. m = S = 0)
      --assign="m,0"
      
      # J held XD (i.e. v = D = 3)
      --assign="v,3"
      

      And then I wrote a short Python program to output the hands dealt.

      The whole thing runs in 64ms.

      Run: [ @replit ]

      from enigma import (SubstitutedExpression, join, printf)
      
      # load the run-file
      p = SubstitutedExpression.from_file("teaser687.run")
      
      # solve the puzzle
      for s in p.solve(verbose=0):
        # output hands
        printf("   A K Q J X")
        hand = lambda xs: join(("SCHD"[s[x]] for x in xs), sep=" ")
        printf("B: {h}", h=hand("abcde"))
        printf("G: {h}", h=hand("fghij"))
        printf("H: {h}", h=hand("kmnpq"))
        printf("J: {h}", h=hand("rstuv"))
        printf()
      

      Solution: George held: A♣, K♦, Q♣, J♠, 10♠.

      The complete set of hands is fully determined:

      B: A♥, K♥, Q♥, J♥, 10♥.
      G: A♣, K♦, Q♣, J♠, 10♠.
      H: A♦, K♠, Q♦, J♦, 10♣.
      J: A♠, K♣, Q♠, J♣, 10♦.

      Like

  • Unknown's avatar

    Jim Randell 10:27 am on 13 July 2021 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 808: Placing the top ten 

    From The Sunday Times, 16th January 1977 [link]

    Last week’s Top Ten consisted of the following performers:

    1. Adda
    2. Bay Leaf Rissolers
    3. Cate Gooseberry
    4. Demi-Sour
    5. Englebert Smith
    6. Fatherhood of Man
    7. Gee-Bees
    8. How
    9. It
    10. John Revolter

    This week the same ten were in the charts, but all their placings were different. Five had gone up and five had gone down. Adda had the biggest single drop of all, but Fatherhood went up.

    When I looked at the products of last week’s and this week’s placings, I found that:

    (a) Gee-Bees’ product was twice Cate Gooseberry’s;
    (b) It’s was three times Demi-Sour’s;
    (c) Englebert’s was even;
    (d) The total of the products was 272.

    What was this week’s order?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book, but modified to remove an error that was introduced in the rewording.

    [teaser808]

     
    • Jim Randell's avatar

      Jim Randell 10:28 am on 13 July 2021 Permalink | Reply

      Here is a solution using the [[ SubstitutedExpression ]] solver from the enigma.py library.

      It runs in 70ms.

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      # if the positions are:
      # last week = 1  2  3  4  5  6  7  8  9  10
      # this week = A  B  C  D  E  F  G  H  I  J
      
      SubstitutedExpression
      
      --base=11
      --digits="1-10"
      
      # no-one kept their spot
      --invalid="1,A"
      --invalid="2,B"
      --invalid="3,C"
      --invalid="4,D"
      --invalid="5,E"
      --invalid="6,F"
      --invalid="7,G"
      --invalid="8,H"
      --invalid="9,I"
      --invalid="10,J"
      
      # "5 went up, 5 went down"
      "sum([A > 1, B > 2, C > 3, D > 4, E > 5, F > 6, G > 7, H > 8, I > 9, J > 10]) == 5"
      
      # "A had the biggest drop of all"
      "A - 1 > max(B - 2, C - 3, D - 4, E - 5, F - 6, G - 7, H - 8, I - 9, J - 10)"
      
      # "F went up"
      "F < 6"
      
      # "G's product was 2 times C's" [not: 3 times]
      "7 * G == 2 * 3 * C"
      
      # "I's product was 3 times D's"
      "9 * I == 3 * 4 * D"
      
      # "E's product was even"
      "(5 * E) % 2 == 0"
      
      # "the total of the products was 272"
      "1 * A + 2 * B + 3 * C + 4 * D + 5 * E + 6 * F + 7 * G + 8 * H + 9 * I + 10 * J == 272"
      
      # [optional]
      --template=""
      

      Solution: (1) John Revolter; (2) Fatherhood of Man; (3) Demi-Sour; (4) It; (5) Bay Leaf Rissolers; (6) Gee-Bees; (7) Cate Gooseberry; (8) Englebert Smith; (9) Adda; (10) How.

      Like

      • Frits's avatar

        Frits 11:54 am on 13 July 2021 Permalink | Reply

        @Jim, “A had the biggest drop of all” : shouldn’t you use the less equal sign in the formula?

        Like

        • Jim Randell's avatar

          Jim Randell 12:02 pm on 13 July 2021 Permalink | Reply

          @Frits: I don’t think so. It would allow another act to have an equally big drop.

          Like

          • Frits's avatar

            Frits 12:09 pm on 13 July 2021 Permalink | Reply

            @Jim: Semantics again. I thought “of all” would make A stand out.

            Like

          • Jim Randell's avatar

            Jim Randell 12:54 pm on 13 July 2021 Permalink | Reply

            I’ve changed it not use not. I want A’s drop to be larger than anyone else’s.

            Like

    • Frits's avatar

      Frits 2:38 pm on 13 July 2021 Permalink | Reply

      Easy to find: C=7, G=6 and D=3, I=4

      A+2B+5E+6F+8H+10J = 161 so A is odd (as E is even).
      So A=9 (A=5 has same single drop as C).

      Ups: G, D, I, F and J so B, E and H must be down.
      So H=10, E=8 and B=5.

      6F + 10J = 22 so F=2 and J=1

      Like

    • GeoffR's avatar

      GeoffR 3:49 pm on 27 July 2021 Permalink | Reply

      I found three constraints, which were correct, but not essential for the single solution.

      % A Solution in MiniZinc 
      include "globals.mzn";
      
      var 1..10:A; var 1..10:B; var 1..10:C; var 1..10:D; var 1..10:E;
      var 1..10:F; var 1..10:G; var 1..10:H; var 1..10:I; var 1..10:J;
      
      constraint all_different ([A,B,C,D,E,F,G,H,I,J]);
      
      % All their placings were different
      constraint A != 1 /\ B != 2 /\ C != 3 /\ D != 4 /\ E != 5
      /\ F != 6 /\ G != 7 /\ G != 8 /\ H != 9 /\ I != 9 /\ J != 10;
      
      % A had the biggest drop of all
      % *** This constraint was correct but not needed for the single solution ***
      % constraint A - 1 > max([B-2, C-3, D-4, E-5, F-6, G-7, H-8, I-9, J-10]);
       
      % F went up
      % *** This constraint was correct but not needed for the single solution ***
      % constraint F < 6;
       
      % G's product was 2 times C's 
      constraint 7 * G == 2 * 3 * C;
       
      % I's product was 3 times D's
      constraint 9 * I == 3 * 4 * D;
       
      % E's product was even
      % *** This constraint was correct but not needed for the single solution ***
      % constraint (5 * E) mod 2 == 0;
      
      % The total of the products was 272.
      constraint 1 * A + 2 * B + 3 * C + 4 * D + 5 * E + 6 
      * F + 7 * G + 8 * H + 9 * I + 10 * J == 272;
      
      % 5 went up, 5 went down
      constraint sum([A > 1, B > 2, C > 3, D > 4, E > 5, F > 6, 
      G > 7, H > 8, I > 9, J > 10]) == 5; 
       
      solve satisfy;
      
      output ["This week’s order is [A,B,C,D,E,F,G,H,I,J] = " 
      ++ show([A,B,C,D,E,F,G,H,I,J]) ];
      
      % [A, B, C, D, E, F, G, H,  I, J] = 
      % [9, 5, 7, 3, 8, 2, 6, 10, 4, 1]
      % ----------
      % ==========
      
      
      
      

      Any more offers on who the 1977 Top Ten performers were meant to be?
      Here is my assessment:

      1. Adda means Abba
      2. Bay Leaf Rissolers means Bay City Rollers
      3. Cate Gooseberry means Kate Bush
      4. Demi-Sour ?
      5. Englebert Smith means Englebert Humperdink
      6. Fatherhood of Man means Brotherhood of Man
      7. Gee-Bees means Bee Gees
      8. How ?
      9. It ?
      10. John Revolter means John Travolta

      Like

      • Jim Randell's avatar

        Jim Randell 7:25 pm on 27 July 2021 Permalink | Reply

        I thought “Demi-Sour” could be “The Sweet” (or possibly “Demis Roussos”), but I didn’t come up with anything for “How” or “It”.

        Like

    • GeoffR's avatar

      GeoffR 8:19 pm on 27 July 2021 Permalink | Reply

      Yes , ” Demis Roussos” sounds good to me for “Demi-Sour”.

      Maybe “How” could be “The Who” ? Just “It” left.

      Like

    • Jim Randell's avatar

      Jim Randell 4:56 pm on 28 July 2021 Permalink | Reply

      I looked through the charts for 1975 and 1976, and “The Who” had singles in the charts then.

      But nothing leapt out at me for “It”. The closest was “If” by “Telly Sevalas”, but that’s the track name rather than the artist name.

      Although, now I realise the names were made for the rewording of the puzzle in the book, so they could be refer to artists in the charts after the puzzle was in published in the newspaper.

      Like

      • Jim Randell's avatar

        Jim Randell 12:56 pm on 30 July 2021 Permalink | Reply

        In late 1977 – 1979 “Chic” were in the charts.

        Both “chic” and “it” are synonyms for “fashionable”.

        Like

    • GeoffR's avatar

      GeoffR 8:22 am on 31 July 2021 Permalink | Reply

      Yes, that looks a good fit.

      The only 1977 track I found was:
      https://www.discogs.com/Kate-Taylor-Its-In-His-Kiss-The-Shoop-Shoop-Song/release/5413526
      (later made famous by Cher, of course)

      Like

  • Unknown's avatar

    Jim Randell 9:54 am on 6 July 2021 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 803: Three perfect squares 

    From The Sunday Times, 5th December 1976 [link]

    To code his message, the Agent began by writing three words — each word being a number, e.g. FIVE. In doing this, he did not write any single letter of the alphabet more than once.

    For each of the letters thus written, he then substituted a digit and, in doing so, he used each of the digits 0 to 9 inclusive once (and once only).

    He now had three numbers (all in figures) each of which was a perfect square. By adding these three numbers together, he obtained a total running to five figures.

    In place of the digits in this total he now wrote the letters for which each of them had originally been substituted. This gave the letters NONSO.

    What were the three perfect squares (in figures)?

    This puzzle is included in the book The Sunday Times Book of Brain-Teasers: Book 1 (1980). The puzzle text above is taken from the book.

    [teaser803]

     
    • Jim Randell's avatar

      Jim Randell 9:54 am on 6 July 2021 Permalink | Reply

      The three numbers used (when considered as words) must use 10 different letters between them, and the result is 5 letters long. So each of the numbers has at most 5 letters. But if one were to have 5 letters, that would only leave 5 letters for the remaining 2 numbers, and there are no numbers with 2 (or fewer) letters. So the numbers must have (4, 3, 3) letters.

      This Python program collects numbers with fewer than 5 letters, and finds 3 of them that between them use 10 different letters (including the letters of NONSO). We then use the [[ SubstitutedExpression ]] solver from the enigma.py library to solve the alphametic sum.

      It runs in 64ms.

      Run: [ @replit ]

      from enigma import irange, int2words, subsets, union, SubstitutedExpression, sprintf, printf
      
      # collect numbers (as words) with fewer than 5 letters
      words = list(x.upper() for x in map(int2words, irange(0, 10)) if len(x) < 5 and x.isalpha())
      
      # choose three words
      for ws in subsets(words, size=3):
        # check there are 10 different symbols (including NOS)
        ss = union(ws)
        if not(len(ss) == 10 and ss.issuperset('NOS')): continue
      
        # solve the alphametic puzzle
        exprs = list(sprintf("is_square({w})") for w in ws)
        t = sprintf("{ws[0]} + {ws[1]} + {ws[2]} = NONSO")
        exprs.append(t)
        p = SubstitutedExpression(exprs, verbose=0)
        for s in p.solve():
          printf("{t} | {s}", s=p.substitute(s, t))
      

      Solution: The three squares are: 9025, 784, 361.

      These correspond to:

      FOUR = 9025 (= 95²)
      SIX = 784 (= 28²)
      TEN = 361 (= 19²)

      Like

    • GeoffR's avatar

      GeoffR 7:28 pm on 6 July 2021 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
      
      % sets of three and four digit squares
      set of int: sq = {n*n | n in 10..99};
      
      % he used each of the digits 0 to 9 inclusive once only
      var 1..9:A; var 0..9:B; var 0..9:C; 
      var 1..9:D; var 0..9:E; var 0..9:F; 
      var 1..9:G; var 0..9:H; var 0..9:I; var 0..9:J; 
      
      constraint all_different([A, B, C, D, E, F, G, H, I, J]);
      
      % 2 no. 3-digit and 1 no. 4-digit squares - ex Jim's analysis
      var 100..999:ABC = 100*A + 10*B + C;
      var 100..999:DEF = 100*D + 10*E + F;
      var 1000..9999:GHIJ = 1000*G + 100*H + 10*I + J;
      
      var 10000..99999:NONSO; % the sum of the three squares
      
      constraint ABC in sq /\ DEF in sq /\ GHIJ in sq;
      
      constraint NONSO ==  ABC + DEF + GHIJ;
      
      % check digit pattern of NONSO for 'N' and 'O'
      constraint NONSO div 10000 == NONSO div 100 mod 10
      /\ NONSO div 1000 mod 10 == NONSO mod 10;
      
      solve satisfy;
      
      output ["Three squares are " ++ show(ABC) ++ ", " ++ show(DEF) 
      ++ ",  " ++ show(GHIJ) ++ "\n" ++ 
      "NONSO, the 5-digit sum = " ++ show(NONSO)];
      
      % Three squares are 361, 784,  9025
      % NONSO, the 5-digit sum = 10170
      % ----------
      % Three squares are 784, 361,  9025
      % NONSO, the 5-digit sum = 10170
      % ----------
      % ==========
      
      
      
      

      Like

      • Frits's avatar

        Frits 6:08 pm on 7 July 2021 Permalink | Reply

        @GeoffR,

        It is not directly stated but I think N, O and S are meant to be different digits. It doesn’t matter for the solution.

        Like

    • John Crabtree's avatar

      John Crabtree 10:31 am on 9 July 2021 Permalink | Reply

      FIVE and NINE only allow one 3-digit number (TWO), and so FOUR is the four-digit number and must contain 0, and, as F = 8 or 9, so must be 9025, 9604 or 9801.
      The sum of the digits of NONSO = 0 mod 9. N = 1. If O = 8, S = 0 which is invalid. If O = 6, S = 4, which is invalid. And so FOUR = 9025, S = 7, ie SIX = 784, which leaves TEN = 361.

      Like

    • GeoffR's avatar

      GeoffR 12:22 pm on 9 July 2021 Permalink | Reply

      # three/four digit squares list
      sq = [x * x for x in range(10, 100)]
      
      digits = set('1234567890')
      
      from itertools import permutations
      
      # 1st stage permutation
      for p1 in permutations('1234567890', 3):
        A, B, C = p1
        if A == '0':
          continue
        ABC = int(A + B + C)
        if ABC not in sq:
          continue
        
        # 2nd stage permutation
        q1 = digits.difference(p1)
        for p2 in permutations(q1, 3):
          X, Y, Z = p2
          if X == '0':
            continue
          XYZ = int(X + Y + Z)
          if XYZ not in sq:
            continue
      
          # 3rd stage permutation
          q2 = q1.difference(p2)
          for p3 in permutations(q2):
            P, Q, R, S = p3
            if P == '0':
              continue
            PQRS = int(P + Q + R + S)
            if PQRS not in sq:
              continue
      
            # form sum of three squares
            NONSO = ABC + XYZ + PQRS
            # check digit pattern of NONSO
            if 10000 < NONSO < 100000:
              if NONSO // 1000 % 10 == NONSO % 10:  # 'O'
                if NONSO // 10000 == NONSO // 100 % 10: # 'N' 
                  print(f"Three Squares are {ABC}, {XYZ}, {PQRS}")
                
      # Three Squares are 361, 784, 9025
      
      
      

      Like

  • Unknown's avatar

    Jim Randell 9:48 pm on 18 November 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 510: [Angling competition] 

    From The Sunday Times, 21st March 1971 [link]

    Announcing that the Baron’s team had won the angling competition, the Mayor told those assembled that the winning catch weighed 19st 1lb 7oz and consisted of plaice, halibut and turbot. He also disclosed the remarkable fact that each fish of the same kind had been precisely the same weight — each plaice 2lb 8oz, each halibut 4lb 1oz and each turbot 6lb 6oz.

    Although His Worship mentioned that half the total number of fish in the winning catch were of one and the same kind and that there were three times as many of one kind as of one other kind, he lamentably failed to give the further details so many were waiting to hear.

    One enthusiast, for example, wished to know the total weight of all the plaice landed by the Baron’s team.

    Can you say what it was? (Answers in lbs).

    This puzzle was originally published with no title.

    [teaser510]

     
    • Jim Randell's avatar

      Jim Randell 9:40 am on 21 November 2019 Permalink | Reply

      Using oz for for measuring weight, we have:

      1 lb = 16 oz
      1 st = 14 lb = 224 oz

      So the total weight of fish is:

      total = 19 st, 1 lb, 7 oz = 4279 oz

      And the individual types of fish weigh:

      plaice = 2 lb, 8 oz = 40 oz
      halibut = 4 lb, 1 oz = 65 oz
      turbot = 6 lb, 6 oz = 102 oz

      This Python program uses the [[ express() ]] function from the enigma.py library. It runs in 110ms.

      from enigma import (express, div, printf)
      
      # find numbers of plaice, halibut, turbot
      for s in express(4279, (40, 65, 102), min_q=1):
        t = sum(s)
        # half the total was of one kind
        h = div(t, 2)
        if h is None or h not in s: continue
        # and there were 3 times as many of one kind than of an other
        if not any(3 * x in s for x in s): continue
        # output solution
        (p, h, t) = s
        printf("plaice = {p}, halibut = {h}, turbot = {t}")
      

      Solution: The total weight of plaice was 82 lb, 8 oz (= 82.5 lb).

      There were 33 plaice (= 1320 oz = 82 lb, 8 oz = 5 st, 12 lb, 8 oz).

      There were 11 halibut (= 715 oz = 44 lb, 11 oz = 3 st, 2 lb, 11 oz).

      There were 22 turbot (= 2244 oz = 140 lb, 4 oz = 10 st, 4 oz).

      Like

  • Unknown's avatar

    Jim Randell 8:14 am on 13 August 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 493: Absorbers 

    From The Sunday Times, 8th November 1970 [link]

    Three men from the Absorbers’ Association, three from Bacchante’s Bank and three from the Convivial Corporation, took a drink together.

    From each concern, one man drank sherry, one gin and one whisky. Of the three choosing sherry, one chose medium, one dry and one extra dry. With gin, one took tonic, one lemon and one vermouth. With whisky, one plain water, one soda water and one dry ginger.

    The dry sherry drinker did not belong to the same concern as the plain water man, nor to the same concern as the vermouth man. The drinkers of dry ginger, lemon and medium sherry were from three different concerns.

    Either the tonic man or plain water man (but not both) was from the Absorbers’ Association. The selectors of soda and vermouth were not colleagues and neither represented Bacchante’s Bank.

    The tonic man belonged either to the same concern as the dry sherry drinker or to the same concern as the medium sherry man.

    Which type of sherry was chosen by a Convivial Corporation man and what did [the] other men from that same concern take with gin and take with whisky?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser493]

     
    • Jim Randell's avatar

      Jim Randell 8:14 am on 13 August 2019 Permalink | Reply

      The solution space is quite small (there are (3!)³ = 216 possible arrangements), so we can just examine them all and eliminate those which don’t satisfy the conditions.

      This Python program runs in 83ms.

      Run: [ @repl.it ]

      from itertools import product
      from enigma import (subsets, printf)
      
      for ((M, D, X), (T, L, V), (W, S, G)) in product(subsets("ABC", size=len, select='P'), repeat=3):
      
        # "The dry sherry drinker did not belong to the same concern as the
        # plain water man, nor to the same concern as the vermouth man"
        if D == W or D == V: continue
      
        # "The drinkers of dry ginger, lemon and medium sherry were from
        # three different concerns"
        if len(set([G, L, M])) != 3: continue
      
        # "Either the tonic man or plain water man (but not both) was from
        # the Absorbers' Association"
        if not ((T == 'A') ^ (W == 'A')): continue
      
        # "The selectors of soda and vermouth were not colleagues and
        # neither represented Bacchante's Bank"
        if S == V or S == 'B' or V == 'B': continue
      
        # "The tonic man belonged either to the same concern as the dry
        # sherry drinker or to the same concern as the medium sherry man"
        if not (T == D or T == M): continue
        
        printf("Sherry: M={M} D={D} X={X}; Gin: T={T} L={L} V={V}; Whisky: W={W} S={S} G={G}")
      

      Solution: The CC men drank extra dry sherry, gin and lemon, whisky and soda.

      The other drinks are:

      AA = medium sherry, gin and vermouth, whisky and water
      BB = dry sherry, gin and tonic, whisky and ginger

      Like

  • Unknown's avatar

    Jim Randell 9:15 am on 11 June 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 483: Absentees 

    From The Sunday Times, 30th August 1970 [link]

    Only seven men still had ammunition. Aden had 1 round, Bill 2 rounds, Cuff 3, Dudd 4, Edge 5, Ford 6 and Good 7. The commander ordered there should always be five of the seven men on duty and that the duty roster should be so arranged that those on duty never had fewer than 17 rounds of ammunition.

    Next day he was told that only four men were on duty. It appeared that three of the five who should have been present were sick and that the four doing duty included two who should have been off. It so happened that the four had between them the same number of rounds as the five would have had.

    The commander had no copy of the duty roster, but he knew how many rounds each of the seven men had.

    He asked how many rounds the four men doing duty had between them. When given the figure the commander said, after some thought, that he could say with certainty who the three absentees were.

    Can you name them?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser483]

     
    • Jim Randell's avatar

      Jim Randell 9:16 am on 11 June 2019 Permalink | Reply

      We can identify the men by the number of rounds each man has.

      Three men are sick, and two provide cover. The remaining two were scheduled to be on duty and actually were on duty.

      This Python program runs in 81ms.

      Run: [ @repl.it ]

      from enigma import (irange, subsets, diff, filter_unique, unpack, printf)
      
      # the numbers of rounds available
      rounds = list(irange(1, 7))
      
      # generate possible (<number of rounds>, <sick>, <cover>)
      def generate():
        T = sum(rounds)
      
        # consider the 3 sick men
        for sick in subsets(rounds, size=3):
          # the number of rounds amongst the sick men is...
          n = sum(sick)
          # and so the total number of rounds on duty is...
          t = T - n
          if (t < 17): continue
          # find 2 men to cover with the same number of rounds
          for cover in subsets(diff(rounds, sick), size=2):
            if not (sum(cover) == n): continue
            yield (t, sick, cover)
      
      # find solutions where...
      (ss, _) = filter_unique(
        generate(),
        # ... if I knew the total number of rounds ...
        unpack(lambda t, s, c: t),
        # ... I could deduce who was sick
        unpack(lambda t, s, c: s),
      )
      
      # output solutions
      for (t, s, c) in ss:
        printf("{t} rounds -> sick = {s}, cover = {c}")
      

      Solution: The three absentees are Aden, Cuff and Dudd.

      A, C, D have 1+3+4 = 8 rounds between them, and are covered by B and F, who also have 2+6 = 8 rounds between them.

      The remaining 2 men, E and G, with 5 + 7 = 12 rounds between them were scheduled to be on duty and were not sick.

      So altogether there were 8 + 12 = 20 rounds on duty.

      Like

  • Unknown's avatar

    Jim Randell 10:48 am on 23 April 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 475: Club lockers 

    From The Sunday Times, 5th July 1970 [link]

    The lockers in one section of the new club-house are numbered 1 to 12 consecutively. Last Saturday, Pitcher arrived without his key. He was surprised to find that his locker could be opened by the key to Putter’s locker which is next to his.

    Pitcher at once saw Wedge, the secretary, and Bunker, the captain. From them he learned that there are only 3 different key patterns for the 12 lockers (patterns A, B and C) and that the total of the numbers on the 4 A lockers is the same as the corresponding total for the 4 B lockers, which is the same as that for the 4 C lockers.

    Wedge also told Pitcher that no two lockers with pattern A keys are adjoining. He added that his own key is of the same pattern as Wood’s and that the total of the numbers on Wood’s and Wedge’s lockers is 16. He further mentioned that of the 3 lockers, other than the captain’s own locker, which can be opened by the captain’s key, the nearest to the captain’s locker is further from the captain’s locker than are 5 (but not more) lockers which cannot be opened by the captain’s key.

    By this time, Pitcher was making for the wall but if the number on Putter’s locker is higher than the number on Wedge’s locker — what is the number on Bunker’s locker?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser475]

     
    • Jim Randell's avatar

      Jim Randell 10:49 am on 23 April 2019 Permalink | Reply

      This Python 3 program runs in 84ms.

      Run: [ @repl.it ]

      from enigma import (irange, subsets, tuples, diff, printf)
      
      # possible locker numbers
      lockers = irange(1, 12)
      
      # find subsets of size 4 that sum to 26 (= sum(lockers) / 3)
      s4s = list(s for s in subsets(lockers, size=4) if sum(s) == 26)
      
      # choose pairs from the given sets
      def pairs(*ss):
        for s in ss:
          yield from subsets(s, size=2)
      
      # choose a set of lockers for key pattern A
      for A in s4s:
        # there are no consecutive numbers in A
        if any(y - x == 1 for (x, y) in tuples(A, 2)): continue
      
        # choose a (disjoint) set that includes Bunker's key
        for X in s4s:
          if set(A).intersection(X): continue
      
          # and the remaining set
          Y = diff(lockers, A + X)
      
          # choose a locker for Bunker
          for b in X:
      
            # find the distance of the nearest other locker to b in X
            d = min(abs(b - x) for x in X if x != b)
      
            # there must be exactly 5 lockers not in X closer to b
            n = sum(abs(b - x) < d for x in lockers if x not in X)
            if not (n == 5): continue
      
            # Wedge's and Wood's lockers (in the same set) sum to 16
            for (w1, w2) in pairs(A, X, Y):
              if not (w1 + w2 == 16): continue
      
              # Pitcher's and Putter's lockers (in the same set) are adjacent
              for (p1, p2) in pairs(A, X, Y):
                if not (p2 - p1 == 1): continue
      
                # all people are different
                if not (len(set((b, w1, w2, p1, p2))) == 5): continue
      
                # Putter's locker has a higher number than Wedge's
                if not (max(p1, p2) > min(w1, w2)): continue
      
                printf("A={A} X={X} Y={Y}, b={b} d={d}, ws=({w1}, {w2}) ps=({p1}, {p2})")
      

      Solution: Bunker has locker number 2.

      The A pattern keys are for lockers (1, 3, 10, 12). The other pattern keys are lockers (2, 7, 8, 9) and (4, 5, 6, 11).

      Wedge and Wood have lockers 5 and 11 (respectively).

      Pitcher and Putter have lockers 7, 8 or 8, 9 (in some order).

      Like

  • Unknown's avatar

    Jim Randell 6:57 am on 12 March 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 463: Betting prices 

    From The Sunday Times, 12th April 1970 [link]

    In the third race, the bookmakers’ prices varied considerably and, in some cases, were unusual. At one time or another up to the start of the race, the odds quoted against one or more of the 9 horses were 2 to 1, 3 to 1, 4 to 1, and all other whole numbers to 1, up to and including 28 to 1 (i.e., 27 different prices in all).

    Just before the “off” the Baron saw his chance. The prices then being offered by different bookmakers were such that, by staking a total of less than £100, and placing a whole number of pounds on each of the 9 runners he was able to ensure that, no matter which horse won, he would make an overall profit of exactly £13.

    One horse was clear favourite. The other 8 were “paired” in the betting (i.e., there were 4 pairs, both horses in each pair being at the same price — the 4 prices all being different).

    How much did the Baron stake in all, and what were the 5 prices at which he placed his bets?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser463]

     
    • Jim Randell's avatar

      Jim Randell 6:58 am on 12 March 2019 Permalink | Reply

      This Python program collects together odds and stakes that would give the same winnings, and then looks for a collection of five that would give a profit of £13 as described.

      It runs in 76ms.

      Run: [ @repl.it ]

      from collections import defaultdict
      from itertools import combinations
      from enigma import irange, printf
      
      # record bets = (odds, stake) by winnings
      d = defaultdict(list)
      
      # consider odds of "X to 1"
      for X in irange(2, 28):
        # if x pounds is bet...
        for x in irange(1, 99):
          # winnings are...
          w = x * (X + 1)
          if w < 22: continue
          if w > 112: break
          d[w].append((X, x))
      
      # numbers of bets at lengthening odds
      ns = (1, 2, 2, 2, 2)
      
      # choose a collection of winnings and odds
      for (w, vs) in d.items():
        # choose 5 different odds
        for bets in combinations(vs, len(ns)):
          # check the winnings = stake + profit
          if not (w == sum(n * x for (n, (_, x)) in zip(ns, bets)) + 13): continue
          # output solution
          printf("winnings = {w} -> (odds, stakes) = {bets}")
      

      Solution: The Baron staked bets totalling £71. The bets were placed at odds of: 3-1, 6-1, 13-1, 20-1, 27-1.

      The bets were:

      £21 at 3-1
      £12 at 6-1 [×2]
      £6 at 13-1 [×2]
      £4 at 20-1 [×2]
      £3 at 27-1 [×2]

      Giving a total stake of £71, and a total winnings of £84 should any single bet come in.

      Like

  • Unknown's avatar

    Jim Randell 10:31 pm on 21 February 2019 Permalink | Reply
    Tags: by: J L Bowles   

    Brain-Teaser 454: Nine holes 

    From The Sunday Times, 25th January 1970 [link]

    The card of the course at Triangle Park Golf Club gives the total length of the first 9 holes as 3,360 yards. Par for the individual holes (numbers 1 to 9 respectively) being 5, 4, 5, 4, 3, 4, 4, 3, 5 (total 37).

    Closer inspection of the card would show that the lengths of the holes (each a whole number of yards) are such that holes 1, 2 and 3 could each form a different side of the same right-angled triangle (Triangle A) and that other right-angled triangles could similarly be formed from lengths equal to those of holes 4, 5 and 6 (Triangle B); 7, 8 and 9 (Triangle C); 1, 4 and 7 (Triangle X); 2, 5 and 8 (Triangle Y) and 3, 6 and 9 (Triangle Z).

    Moreover, the total length of the three holes forming Triangle A, the total length of the three holes forming Triangle B, and the total length of the three holes forming Triangle C could similarly form the three sides of another right-angled triangle (Triangle ABC) while yet another right-angled triangle could similarly be constructed from the total lengths of the holes forming triangles X, Y and Z (Triangle XYZ).

    In triangle ABC the sides would be in the ratio 5:3:4.

    The length of each of the par 3 holes is between 150 and 250 yards (one being 168 yards); the par 4 holes are between 250 and 450 yards; and the par 5 holes are between 475 and 600 yards (one being 476 yards).

    What are the lengths of holes 2, 6 and 7?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser454]

     
    • Jim Randell's avatar

      Jim Randell 10:33 pm on 21 February 2019 Permalink | Reply

      This Python program uses the [[ pythagorean_triples() ]] function from the enigma.py library to find appropriate triangles. (Originally written for Teaser 2910).

      Run: [ @replit ]

      from enigma import (defaultdict, pythagorean_triples, sq, printf)
      
      # par for distance x
      def par(x):
        if 149 < x < 251: return 3
        if 249 < x < 451: return 4
        if 474 < x < 601: return 5
      
      # find triangles in the appropriate classes
      ts = defaultdict(list)
      for t in pythagorean_triples(600):
        k = tuple(par(x) for x in t)
        if None not in k:
          ts[k].append(t)
      
      # select tuples from d[k] ordered by indices in ss
      def select(d, k, ss):
        for x in d[k]:
          for s in ss:
            yield tuple(x[i] for i in s)
      
      # does (x, y, z) form a right-angled triangle
      def is_triangle(x, y, z):
        return sq(x) + sq(y) + sq(z) == 2 * sq(max(x, y, z))
      
      
      # choose triangle A (5, 4, 5)
      for (d1, d2, d3) in select(ts, (4, 5, 5), [(1, 0, 2), (2, 0, 1)]):
      
        # choose triangle B (4, 3, 4)
        for (d4, d5, d6) in select(ts, (3, 4, 4), [(1, 0, 2), (2, 0, 1)]):
      
          # choose triangle C (4, 3, 5)
          for (d7, d8, d9) in select(ts, (3, 4, 5), [(1, 0, 2)]):
      
            # check the total distance
            if not (sum((d1, d2, d3, d4, d5, d6, d7, d8, d9)) == 3360): continue      
      
            # check the other triangles
            (X, Y, Z) = ((d1, d4, d7), (d2, d5, d8), (d3, d6, d9))
            ABC = (d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9)
            XYZ = (d1 + d4 + d7, d2 + d5 + d8, d3 + d6 + d9)
            if not all(is_triangle(*t) for t in (X, Y, Z, ABC, XYZ)): continue
      
            # check ABC is a 3, 4, 5 triangle
            if not (5 * min(ABC) == 3 * max(ABC)): continue
      
            # check the given pars
            if not (168 in (d5, d8) and 476 in (d1, d3, d9)): continue
      
            printf("d1={d1} d2={d2} d3={d3} / d4={d4} d5={d5} d6={d6} / d7={d7} d8={d8} d9={d9}")
      

      Solution: Hole 2 is 280 yards. Hole 6 is 357 yards. Hole 7 is 420 yards.

      There is only one solution:

      Hole 1 = 525 yards
      Hole 2 = 280 yards
      Hole 3 = 595 yards
      Hole 4 = 315 yards
      Hole 5 = 168 yards
      Hole 6 = 357 yards
      Hole 7 = 420 yards
      Hole 8 = 224 yards
      Hole 9 = 476 yards

      In fact if the triangle constraints for A, B, C, X, Y, Z, ABC, XYZ are satisfied, there is only a single solution even if the conditions for the total distance, ratios for ABC, and the specific distances for par 3 and 5 are ignored (lines 38, 47, 50).

      Like

      • Jim Randell's avatar

        Jim Randell 9:53 am on 23 February 2019 Permalink | Reply

        This puzzle is a good candidate for solving with a declarative set of constraints.

        Here is a MiniZinc model, that is run via the minizinc.py module. It solves the puzzle in 93ms.

        %#! python3 -m minizinc use_embed=1
        
        % hole distances
        {var("150..250", ["d5", "d8"])};  % par 3
        {var("250..450", ["d2", "d4", "d6", "d7"])};  % par 4
        {var("475..600", ["d1", "d3", "d9"])};  % par 5
        
        % total distance
        constraint d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 + d9 = 3360;
        
        % right angled triangle constraints
        predicate is_triangle(var int: a, var int: b, var int: c) =
          pow(a, 2) + pow(b, 2) + pow(c, 2) = pow(max([a, b, c]), 2) * 2;
        
        constraint is_triangle(d1, d2, d3); % triangle A
        constraint is_triangle(d4, d5, d6); % triangle B
        constraint is_triangle(d7, d8, d9); % triangle C
        
        constraint is_triangle(d1, d4, d7); % triangle X
        constraint is_triangle(d2, d5, d8); % triangle Y
        constraint is_triangle(d3, d6, d9); % triangle Z
        
        constraint is_triangle(d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9); % triangle ABC
        constraint is_triangle(d1 + d4 + d7, d2 + d5 + d8, d3 + d6 + d9); % triangle XYZ
        
        % ABC is a 3, 4, 5 triangle
        constraint 5 * min([d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9]) = 3 * max([d1 + d2 + d3, d4 + d5 + d6, d7 + d8 + d9]);
        
        % some lengths are given
        constraint d5 = 168 \/ d8 = 168;  % par 3
        constraint d1 = 476 \/ d3 = 476 \/ d9 = 476;  % par 5
        
        solve satisfy;
        

        Like

    • GeoffR's avatar

      GeoffR 11:07 am on 23 February 2019 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
      
      % The nine holes are H1..H9 with Par distances as below:
      var 475..600: H1; var 250..450: H2; var 475..600: H3; % Par 5, 4, 5
      
      var 250..450: H4; var 150..250: H5; var 250..450: H6; % Par 4, 3, 4
      
      var 250..450: H7; var 150..250: H8; var 475..600: H9; % Par 4, 3, 5
      
      % Given hole distances
      constraint H5 == 168 \/ H8 == 168;
      constraint H1 == 476 \/ H3 == 476 \/ H9 == 476;
      
      % Total distance for all holes
      constraint H1 + H2 + H3 + H4 + H5 + H6 + H7 + H8 + H9 == 3360;
      
      % Triangle A - H1 and H3 are both Par 5
      constraint (H2 * H2 + H3 * H3 == H1 * H1) \/(H2 * H2 + H1 * H1 == H3 * H3);
      
      % Triangle B - H4 and H6 are both Par 4
      constraint( H5 * H5 + H6 * H6 == H4 * H4) \/ (H5 * H5 + H4 * H4 == H6 * H6);
      
      % Triangle C - H9 is higher Par than H7 or H8
      constraint (H7 * H7 + H8 * H8 == H9 * H9);
      
      % % Triangle X - H1 is higher Par than H4 or H7
      constraint H4 * H4 + H7 * H7 == H1 * H1;
      
      % % Triangle Y - H2 is higher Par than H5 and H8
      constraint (H8 * H8 + H5 * H5 = H2 * H2); 
      
      % % Triangle Z - H3 and H9 are both Par 5
      constraint (H6 * H6 + H9 * H9 == H3 * H3)\/ (H3 * H3 + H6 * H6 == H9 * H9);
      
      % Triangle ABC sides
      var 500..2000: A1;
      var 500..2000: B1;
      var 500..2000: C1;
      
      constraint A1 = H1 + H2 + H3;
      constraint B1 = H4 + H5 + H6;
      constraint C1 = H7 + H8 + H9;
      
      % Sides are in ratio 5:4:3
      constraint A1 mod 5 == 0 \/ B1 mod  5 == 0 \/ C1 mod 5 == 0;
      constraint A1 mod 4 == 0 \/ B1 mod  4 == 0 \/ C1 mod 4 == 0;
      constraint A1 mod 3 == 0 \/ B1 mod  3 == 0 \/ C1 mod 3 == 0;
      
      constraint (A1 * A1 + B1 * B1 == C1 * C1)
      \/ (A1 * A1 + C1 * C1 == B1 * B1)
      \/ (B1 * B1 + C1 * C1 == A1 * A1);
      
      % Triangle XYZ sides
      var 500..4000: X1;
      var 500..4000: Y1;
      var 500..4000: Z1;
      
      constraint X1 = H1 + H4 + H7;
      constraint Y1 = H2 + H5 + H8;
      constraint Z1 = H3 + H6 + H9;
      
      constraint (X1 * X1 + Y1 * Y1 == Z1 * Z1)
      \/ (X1 * X1 + Z1 * Z1 == Y1 * Y1)
      \/ (Y1 * Y1 + Z1 * Z1 == X1 * X1);
      
      solve satisfy;
      
      % H1 = 525; H2 = 280; H3 = 595;  Holes H1..H9 lengths (yd)
      % H4 = 315; H5 = 168; H6 = 357;
      % H7 = 420; H8 = 224; H9 = 476;
      % Solution: H2 = 280, H6 = 357, H7 = 420
       
      % A1 = 1400; B1 = 840; C1 = 1120;  Triangle ABC sides
      % X1 = 1260; Y1 = 672; Z1 = 1428;  Triangle XYZ sides
      % ----------
      % ==========
      % Finished in 237msec
      
      

      Like

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
Design a site like this with WordPress.com
Get started