Tagged: by: C Skeffington Quin Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 10:37 am on 29 June 2023 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brainteaser 1093: Bumper’s final ball 

    From The Sunday Times, 17th July 1983 [link]

    It is a lovely evening in August, and the final Test of the 1990 series has reached its climax. The rubber stands at two games each, the last ball of the last over of the match is now to come. Australia are batting and need six runs for victory. Whacker, their wicket-keeper, the last man in, has taken his stand. with his captain’s words ringing in his ears, “Six or bust!”.

    Bumper, the England bowler, has just taken the previous two wickets in succession, With a dim opinion of Whacker’s batting, he feels sure that a fast straight one will not only give England the Ashes, but will give him his hat-trick and his seventh wicket of the match.

    In a breathless hush he delivers a  fast straight one. Striding forward like a Titan, Whacker mows …

    The records of this match are scanty. The Australian total in two innings was 490. Except for one man run out in the first innings, their casualties fell to bowlers. The five England bowlers had averages of 14, 20, 25 (Bumper), 33, 43, each with a differing number of wickets.

    How many wickets did each take and who won the Ashes?

    This puzzle was originally published as Brain-Teaser 15 on 11th June 1961 (although when originally published it was credited to R. Skeffington Quinn), and was re-published as Brainteaser 1093 to celebrate Mr Skeffington Quin’s 100th birthday.

    [teaser1093]

     
    • Jim Randell's avatar

      Jim Randell 10:38 am on 29 June 2023 Permalink | Reply

      See my solution at Teaser 15.


      In the same issue an interview with Mr Skeffington Quin was published. [link]

      The article notes that Mr Skeffington Quin’s “very first” puzzle (Brain-Teaser 15, 11th June 1961) is being re-published (as Brainteaser 1093) in celebration of his 100th birthday.

      However in 1960, the year before Brain-Teaser became a weekly feature (and before the puzzles were numbered), he had contributed a puzzle on 31st July 1960 (Brain-Teaser: Silver collection), which was also included in the book Sunday Times Brain Teasers (1974).

      The article also mentions a puzzle set on 5th November 1972 as his most “impenetrable” puzzle, and that only two correct answers were received.

      However when I searched for this puzzle in The Sunday Times archive, I found a note saying that The Sunday Times was not published on that date due to industrial action. (However the accompanying magazine, which was prepared in advance, is present in the archive, but the puzzle does not appear in it).

      However there is a gap in the puzzle numbers at that point (the missing puzzle is Brain-Teaser 591), and a solution was given with Brain-Teaser 593, where it is noted that only 2 (out of 50) entrants got the correct answer, suggesting the puzzle was published.

      So it is indeed something of a puzzle.

      Like

    • GeoffR's avatar

      GeoffR 6:52 pm on 29 June 2023 Permalink | Reply

      
      % A Solution in MiniZinc
      include "globals.mzn";
       
      % Number of wickets taken by each bowler is different
      var 1..9:w1; var 1..9:w2; var 1..9:w3;  
      var 1..9:w4; var 1..9:w5; 
      constraint all_different([w1, w2, w3, w4, w5]);
      
      % Average runs per wicket for each bowler
      int: a1 == 14;
      int: a2 == 20;
      int: a3 == 25;  % Bumper's average runs per wicket 
      int: a4 == 33;
      int: a5 == 43;
      
      % total runs for each bowler ( say, UB half total runs scored)
      var 1..245:t1; var 1..245:t2; var 1..245:t3; var 1..245:t4; var 1..245:t5;
      
      % The Australian total in two innings was 490
      constraint  t1 + t2 + t3 + t4 + t5 == 490;
      
      constraint a1 * w1 == t1 /\ a2 * w2 == t2 /\ a3 * w3 == t3 /\ 
      a4 * w4 == t4 /\ a5 * w5 == t5;
      
      % Bumper (w3) takes 6 or 7 wickets (Jim's analysis)
      % .. and total wickets are 18 or 19
      constraint ((w1 + w2 + w3 + w4 + w5 == 18) /\ w3 == 6)
      \/  ((w1 + w2 + w3 + w4 + w5 == 19) /\ w3 == 7);
      
      solve satisfy; 
      
      output [ "[w1, w2, w3, w4, w5 ] = " ++ show( [w1, w2, w3, w4, w5 ]) ++
      "\n" ++ "[t1, t2, t3, t4, t5 ] = " ++ show( [t1, t2, t3, t4, t5 ]) ++
      "\n" ++ "[a1, a2, a3, a4, a5 ] = " ++ show( [a1, a2, a3, a4, a5 ])];
      
      % [w1, w2, w3, w4, w5 ] = [5, 2, 7, 1, 4]
      % [t1, t2, t3, t4, t5 ] = [70, 40, 175, 33, 172]
      % [a1, a2, a3, a4, a5 ] = [14, 20, 25, 33, 43]
      % ----------
      % ==========
      % so Bumper takes 7 wickets and England wins the series.
      
      % Not sure of relevance of condition below
      % Bumper, the England bowler, has just taken the previous two wickets in succession,
      
      

      Like

    • Pete Good's avatar

      Pete Good 1:23 pm on 19 September 2023 Permalink | Reply

      Jim,

      I may be able to shed some light on the missing Skeffington-Quin teaser. I first started doing Brain Teasers when I was at school and one puzzle that I particularly remember was “Here Comes the Bride” by this author. I remember it because the Sunday Times printed a note in the magazine a few weeks later stating that there were only 2 correct entries out of 50. I kicked myself at the time for not having sent in a postcard because I had obtained the correct solution!

      I never kept copies of those early newspapers so I was delighted when I recently obtained a second-hand copy of Ronnie Postill’s 1974 book of Brain Teasers and had the pleasure of solving it again. I thought it was originally published in 1968 or 1969, not in 1972 as stated in the article you read. If you have access to the Sunday Times archives then you may find it in an earlier year.

      Regards

      Pete

      Like

      • Jim Randell's avatar

        Jim Randell 6:43 pm on 19 September 2023 Permalink | Reply

        @Pete: Thanks for the info.

        I also have a copy of the 1974 book, and I have gradually been adding puzzles from it to the site – [teaser-book-1974]. There are currently 44 (of 101) puzzles posted from that book, but I haven’t yet got to the one you mention, which is Teaser 429 (27th July 1969). When the answer was published (10th August 1969) it was noted that there were 21 correct entries.

        I searched the Sunday Times Digital Archive for puzzles involving Ara and Chne, and found these:

        Brain-Teaser 250: Spider’s Wedding March / 13th February 1966
        Brain-Teaser 346: Antics / 24th December 1967 (also in the 1974 book)
        Brain-Teaser 429: Here Comes the Bride / 27th July 1969 (also in the 1974 book)
        Brain-Teaser 843: Stratagem / 11th September 1977

        but it didn’t find the missing puzzle, Brain-Teaser 591 (5th November 1972), so the search continues.

        Like

  • Unknown's avatar

    Jim Randell 10:08 am on 25 June 2023 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 346: Antics 

    From The Sunday Times, 24th December 1967 [link]

    All distances and dimensions are exact feet; all times, exact seconds; all the spiders run at 5 feet per second; and drop with a maximum fall of 30 feet.

    Ara and Chne sat hungry in the top north-west corner of the palace corridor (no flies).

    “Could be and ant or two in that bottom south-east corner by the garden door”, said Chne.

    “True”, said Ara. She dropped to the floor and headed straight for the prospective meal, while Chne (she never drops) instantly set off down the shortest route via the north wall and floor.

    Farther along the corridor, Taran and Tula sat hungry together at the top of the south wall.

    “Hey, look!”, cried Taran, as the ant-hunters approached.

    “Must be something in that corner”, said Tula, dropping to the floor and speeding straight toward it.

    Taran at the same moment ran direct for the corner. As she started, Ara, clocking 39 seconds, passed by.

    Tangle and wrangle! Dead heat all! No ants!

    How wide is the corridor?

    This puzzle is included in the book Sunday Times Brain Teasers (1974). The puzzle text is taken from the book.

    [teaser346]

     
    • Jim Randell's avatar

      Jim Randell 10:09 am on 25 June 2023 Permalink | Reply

      By folding the walls of the corridor flat we can turn all of the paths into straight lines in the same plane.

      Measuring all distances in feet, and times in “ticks” (= 1/5 second), then each spider travels 1 ft per tick.

      We don’t know how long it takes a spider to drop the height of the corridor, but this is calculated as part of the solution.

      The following Python program runs in 58ms. (Internal runtime is 859µs).

      Run: [ @replit ]

      from enigma import (pythagorean_triples, sum_of_squares, is_square, printf)
      
      # consider the path Taran takes, it is the hypotenuse of a Pythagorean triple
      for (a, b, t2) in pythagorean_triples(999):
        # but must be divisible by 5
        if t2 % 5 > 0: continue
        # and the height of the corridor must be no more than 30
        for (h, t1) in [(a, b), (b, a)]:
          # and Tula's path must also be a multiple of 5
          if h > 30 or t1 % 5 > 0: continue
          # and their times are equal, so we can calculate drop time (in 1/5 s)
          d = t2 - t1
      
          # total time for Ara and Chne is 195 ticks more than for t2
          t = t2 + 195
          # and this is Chne's distance, the hypotenuse of a (w + h, l, t) triangle
          for (x, y) in sum_of_squares(t * t, min_v=1):
            for (wh, l) in [(x, y), (y, x)]:
              w = wh - h
              if w < 0 or not (l > t1): continue
              # Ara's time is the same as Chne's
              z = is_square(w * w + l * l)
              if z is None or z + d != t: continue
      
              # output solution
              printf("h={h} t1={t1} t2={t2}; d={d} t={t}; w={w} l={l} z={z}")
      

      Solution: The corridor is 39 ft wide.

      And 25 ft high, and 252 ft long.

      Chne takes a direct route (across the N wall and floor) so travels hypot(39 + 25, 252) = 260 ft (in 52s).

      Ara drops to the floor (which takes 1s) and travels hypot(39, 252) = 255 ft (in 51s).

      At the 39s mark Taran and Tula set off on their journeys.

      Taran crosses the S wall diagonally for 13s, so travels a distance of 65 ft.

      Tula drops to the floor (1s) and travels for 12s a distance of 60 ft.

      And so they all arrive in the SE bottom corner at exactly the same time.

      Like

  • Unknown's avatar

    Jim Randell 11:06 am on 5 February 2023 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 180: [Crates of books] 

    From The Sunday Times, 20th September 1964 [link]

    A publisher dispatches crates of mixed books to retailers — Adventure (high price), Biography (medium price), and Crime (low price). The crates each contain an equal number of books, but, conforming to local tastes, all have different proportions of the three books, and in fact, within the invoice price of £54 per crate it takes exactly every possible combination of the three to supply his customers.

    On taking stock he finds that to each 2 of A, he has sold 3 each of B and C.

    Weeks later, to the same customers, and under the same conditions, he despatches a similar consignment, except that on this occasion the three books have a wider price range. One of the crates, however, is mistakenly packed in proportion: A:B:C = 4:3:2, instead of A:B:C = 3:2:4.

    What is the true total value of this consignment?

    (All book prices are exact shillings).

    This puzzle was originally published with no title.

    [teaser180]

     
    • Jim Randell's avatar

      Jim Randell 11:07 am on 5 February 2023 Permalink | Reply

      When the solution was published it was noted: “Only 43 attempted this “fifth-form” Brain-teaser (180) and only 15 accurately solved it”.

      However I did find it was necessary to add the following conditions to arrive at a unique solution:

      (1) there is at least 1 copy of each type of book in each crate; and:
      (2) there are at least 3 crates in each consignment

      The two consignments are to the same customers, so presumably consist of the same number of crates, the same number of books per crate, the same value per crate, and the same distribution of books per crate.

      Each crate contains books to a value of £54. At 20 shillings per pound this is 1080 shillings. (All following values are given in shillings).

      Each create contains the same number of books say n, and the incorrectly packed crate is meant to be packed with books in the ratio A:B:C = 3:2:4, so n must be a multiple of 9 (say 9k).

      So, given a value for n, we can determine the how many of each book are meant to be in the incorrectly packed crate, and consider prices that give the crate a total value of 1080. Then using these prices we can determine how many different packings there are (assuming at least 1 book of each type per crate), which gives us the total number of crates in each consignment. (And at this point I also found it necessary to assume that there were at least 3 crates in a consignment). We can then determine the total number of books of each type in the entire consignment, and check that these are in the ratio A:B:C = 2:3:3.

      From these potential prices and packings we can select two candidates, one with a narrower range of prices and one with a wider range of prices. And we can then calculate the actual value of the incorrectly packed crate in the consignment with the wider price range to give the required answer.

      This Python program runs in 1.91s.

      from enigma import (irange, inf, div, express, rev, unpack, unzip, ratio, subsets, printf)
      
      # construct prices (pA, pB, pC), such that: pA > pB > pC, for
      # quantities of books (nA, nB, nC) with a total value of t
      def prices(nA, nB, nC, t):
        # choose a price for the most expensive books
        for pA in irange(3, inf):
          r1 = t - pA * nA
          if r1 < 0: break
          # choose a price for the cheapest books
          for pC in irange(1, pA - 2):
            r2 = r1 - pC * nC
            if r2 < 0: break
            # calculate the price of the mid-prices books
            pB = div(r2, nB)
            if pB and pA > pB > pC:
              yield (pA, pB, pC)
      
      # construct numbers of books (nA, nB, nC) priced at (pA, pB, pC)
      # such that: nA + nB + nC = n, and the total value of the crate is t
      def crates(n, pA, pB, pC, t):
        for qs in express(t, [pC, pB, pA], min_q=1):
          if sum(qs) == n:
            yield rev(qs)
      
      # consider the number of books per crate (is a multiple of 9, say 9k)
      for k in irange(1, 63):
        # number of intended books in the incorrectly packed crate
        (nA, nB, nC) = (3 * k, 2 * k, 4 * k)
        n = nA + nB + nC
      
        # find possible prices, sorted by price range (narrow to wide)
        ps = list(prices(nA, nB, nC, 1080))
        # we need at least 2 different prices
        if len(ps) < 2: continue
      
        # for each set of prices consider all possible crate packings
        # and record those that give total numbers of books in the consigment
        # in the ratio A:B:C = 2:3:3
        rs = list()
        for (pA, pB, pC) in ps:
          # find all possible crate packings
          cs = list(crates(n, pA, pB, pC, 1080))
          if len(cs) < 3: continue  # require at least 3 different packings
          # sum the total numbers of books in the consignment
          (tA, tB, tC) = map(sum, unzip(cs))
          if ratio(tA, tB, tC) == (2, 3, 3):
            rs.append((pA, pB, pC, cs))
        if len(rs) < 2: continue
      
        # sort results by price range (narrow to wide)
        prange = unpack(lambda pA, pB, pC, cs: pA - pC)
        rs.sort(key=prange)
      
        # choose pairs with narrow and wide price ranges
        for (nr, wr) in subsets(rs, size=2):
          if not prange(nr) < prange(wr): continue
          # output solution
          printf("{n} books per crate")
          for (i, (pA, pB, pC, cs)) in enumerate((nr, wr), start=1):
            printf("[consignment {i}] prices (A, B, C) = ({pA}, {pB}, {pC})")
            tv = 0
            for (nA, nB, nC) in cs:
              v = nA * pA + nB * pB + nC * pC
              printf("-> crate (A, B, C) = ({nA}, {nB}, {nC}); value = {v}")
              if i == 2 and ratio(nA, nB, nC) == (3, 2, 4):
                v = nC * pA + nA * pB + nB * pC
                printf("--> packed as (A, B, C) = ({nC}, {nA}, {nB}); value = {v}")
              tv += v
            printf("total value of consignment = {tv}")
            printf()
      

      Solution: The total value of the second consignment is 5672s (= £283 + 12s).


      If the books are priced: A=21, B=16, C=10, then with 72 books per crate, we can make the following (A, B, C) crates contain books with a value of 1080s:

      (6, 49, 17)
      (12, 38, 22)
      (18, 27, 27)
      (24, 16, 32) [*]
      (30, 5, 37)

      The total number of books of each type in the consignment is (90, 135, 135) which are in the ratio 2:3:3.

      And the indicated crate [*] has books in the ratio 3:2:4.

      The total value of the shipment is 5× 1080 = 5400.

      If the prices of the books are subsequently changed to: A=27, B=17, C=5 (a wider price range), then the same set of crates can be made, and each crate still contains 72 books with a value of 1080.

      But in the second consignment the 72 books in the starred crate [*] are incorrectly packed as (32, 24, 16).

      Meaning there are 8 more copies of A, 8 more copies of B, and 16 fewer copies of C.

      So the actual total value of the second shipment is: 8×27 + 8×17 − 16×5 = 272 more than before, i.e. 5400 + 272 = 5672.


      Without the requirement that there are at least 3 crates in a shipment we can find additional solutions, such as:

      36 books per crate
      [consignment 1] prices (A, B, C) = (36, 31, 25)
      → crate (A, B, C) = (6, 19, 11); value = 1080
      → crate (A, B, C) = (12, 8, 16); value = 1080
      total value of consignment = 2160

      [consignment 2] prices (A, B, C) = (42, 32, 20)
      → crate (A, B, C) = (6, 19, 11); value = 1080
      → crate (A, B, C) = (12, 8, 16); value = 1080
      → → packed as (A, B, C) = (16, 12, 8); value = 1216
      total value of consignment = 2296

      Which may account for some of the incorrect entries received at the time.

      Like

  • Unknown's avatar

    Jim Randell 2:04 pm on 24 July 2022 Permalink | Reply
    Tags: by: C Skeffington Quin,   

    Brain-Teaser 159: Fallen leaves 

    From The Sunday Times, 26th April 1964 [link]

    Three leaves fall from a book. The total of the page numbers remaining in the second half of the book is now three times the total of the page numbers remaining in the first half.

    The total of the page numbers on the fallen leaves lies between 1050 and 1070, and is the highest which could have produced this effect.

    How many numbered pages did the book contain originally?

    I found many solutions, which improve on the published answer. So I have marked the puzzle as flawed.

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

    [teaser159]

     
    • Jim Randell's avatar

      Jim Randell 2:06 pm on 24 July 2022 Permalink | Reply

      I think this puzzle is flawed, as I found many solutions that seem to satisfy the puzzle text, and are different from the published solution.

      If we suppose the book consists of n leaves (= 2n pages), and that the leaves are 1|2, 3|4, …, (2n − 1)|(2n).

      And the two halves of the book are pages 1 – n and (n + 1)(2n).

      Then the initial sum of page numbers in each half of the book are:

      first half = sum(1 .. n) = n(n + 1)/2
      second half = sum(n+1 .. 2n) = n(3n + 1)/2

      Now, if the three leaves removed are (2a − 1)|(2a), (2b − 1)|(2b), (2c − 1)|(2c).

      Then the total of the page numbers removed is t = 4(a + b + c) − 3, and this is in the range 1050 – 1070.

      So (a + b + c) is in the range 264 – 268, and we want this to take on the highest possible value (i.e. 268 if possible, which corresponds to t = 1069).

      If the sum of the removed pages in the first and second halves is t1, t2 (t1 + t2 = t), then we have:

      n(3n + 1)/2 − t2 = 3(n(n + 1)/2 − t1)
      n = 3.t1 − t2

      This Python program starts looking for values of t from 268 down to 264, and stops when it finds a value that gives viable books. It runs in 74ms. And it finds many possible solutions.

      from enigma import (irange, decompose, printf)
      
      # solve with leaves removed (even page numbers given)
      def solve(*vs):
        # calculate the removed page numbers
        (x, y, z) = (2 * v for v in vs)
        ps = (x - 1, x, y - 1, y, z - 1, z)
        # split the pages at index i
        for i in irange(2, 4):
          t1 = sum(ps[:i])
          t2 = sum(ps[i:])
          # calculate the number of leaves (so there are 2n pages)
          n = 3 * t1 - t2
          if n < 3 or ps[-1] > 2 * n: continue
          # and check the split occurs between the halves
          if i > 0:
            if ps[i - 1] > n: continue
          if i < 6:
            if not (ps[i] > n): continue
          yield (n, ps, t1, t2)
      
      # record solutions (number of pages = twice the number of leaves)
      ss = set()
      
      # t = a + b + c
      for t in irange(268, 264, step=-1):
        # calculate possible a, b, c values
        for (a, b, c) in decompose(t, 3):
          for (n, ps, t1, t2) in solve(a, b, c):
            printf("[t={t}: a={a} b={b} c={c} -> {ps}; t1={t1} t2={t2}; n={n}]")
            ss.add(2 * n)
        # are we done?
        if ss:
          printf("pages = {ss}", ss=sorted(ss))
          break
      

      Solution: The book could have: 310, 318, 342, 350, 374, 406, 438, 470, 502, 534, 566, 598, 630, 662, 694, 6414 pages.


      Here is one of the solutions found:

      If the book has 203 leaves = 406 pages, numbered 1|2, 3|4, …, 203|204, …, 405|406.

      Then the sum of the page numbers in the first half of the book is: sum(1..203) = 20706.

      And the sum of the page numbers in the second half of the book is: sum(204..406) = 61915.

      (Note that if leaf 203|204 is removed, that is one page from each half of the book).

      Now, if pages 1|2, 157|158, 375|376 are removed (total = 1069, the largest possible value).

      Then the pages removed from the first half are: 1, 2, 157, 158; sum = 318, so the sum of the remaining pages in the first half is 20706 − 318 = 20388.

      And the pages removed from the second half are: 375, 376; sum = 751, so the sum of the remaining pages in the second half is 61915 − 751 = 61164.

      And: 61164 = 3 × 20388, as required.


      The published solution (and that given in the 1974 book) is that the book initially had 302 pages (i.e. 151 leaves), and the removed pages are 75|76, 151|152, 301|302. Which gives a total of 1057.

      But I have shown above that this is not the largest total possible.

      It was also noted: “Only 4 correct answers in a very small entry”. So it seems I wasn’t the only one that had issues with this puzzle.

      The solution in the book only considers 3 ways that leaves can be removed: 1 from the first half + 2 from the second half; 2 from the first half + 1 from the second half; 1.5 from each half. In terms of pages these are 2+4, 3+3, 4+2, but my program also considers 0+6, 1+5, 5+1, 6+0. However the example I give is a 4+2 combination, which should be accounted for by the published solution. But it has arrived at the conclusion that the maximum viable total of the numbers on the removed pages for a book with x leaves is 7x, so 1057 is the maximum possible (with 151 leaves), but I think this is faulty reasoning.

      (The only thing I can think of is that the two halves of the book are considered after the leaves have been removed. (Although the solution given in the book doesn’t seem to support this). But even with this interpretation there are multiple solutions with a total of 1069 – any that removes 3 pages from the first half and three from the second half will leave the boundary unchanged).

      Like

  • Unknown's avatar

    Jim Randell 3:11 pm on 19 June 2022 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 77: Ali’s counter move 

    From The Sunday Times, 16th September 1962 [link]

    Ali and Baba are playing the Chay game, Ali has a bag containing 12 numbered tickets, 3 each of numbers 1, 2, 3, 4 (all numbers represented by strokes). Baba has 6 double-sided counters containing the same 12 numbers, and a board of 6 squares.

    Ali draws 6 tickets from his bag one at a time, calling out the number as he does so. At each call Baba selects a counter with that number on one of its sides and places it face up in a square. If in 6 calls he fills 6 squares he wins. Once a counter is laid it stays. The counter-couplings are so arranged that 5 squares could always be filled if the numbers were known beforehand.

    But, unnoticed by Baba, Ali has slyly added 1 stroke each to 2 of his opponent’s counters. As a result, Baba frequently places no more than 3 or 4 counters, and at last comes a deal when, after Ali has called “Two”, “One”, he calls a third number and Baba cannot fill it.

    It is the last straw.

    Baba, having lost many pice and much temper, angrily examines the four remaining counters. Three of them are identical couplings!

    “Ah! wicked one”, he cries, “you have forged my counters!”. And, throwing them down, he clears for action.

    What couplings are on these 4 counters?

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

    [teaser77]

     
    • Jim Randell's avatar

      Jim Randell 3:14 pm on 19 June 2022 Permalink | Reply

      This Python program considers possible sets of counters that meet the specified conditions, and looks at ways to fake two of the counters so that there are 3 counters the same. We then match two of the fake set to the calls “1” and “2” and look to see if there is a third call that cannot be matched from the remaining counters. (It is a good opportunity to do some work with multisets).

      This Python program runs in 295ms.

      Run: [ @replit ]

      from enigma import (multiset, irange, subsets, product, union, printf)
      
      # update multiset <m>, by removing values in <rem>, and adding values in <add>
      def update(m, rem=None, add=None):
        if rem:
          m = m.difference(multiset.from_seq(rem))
        else:
          m = m.copy()
        if add:
          m.update_from_seq(add)
        return m
      
      # partition the multiset into <k>-tuples
      # return a multiset of <k>-tuples
      def mpartitions(m, k, ss=[]):
        # are we done?
        if not m:
          yield multiset.from_seq(ss)
        else:
          # choose the next <k>-tuple
          for s in subsets(m, size=k, select="mC"):
            t = tuple(sorted(s))
            if (not ss) or not (t < ss[-1]):
              yield from mpartitions(update(m, rem=s), k, ss + [t])
      
      # the tickets
      tickets = multiset.from_seq([1, 2, 3, 4], count=3)
      
      # possible sequences of tickets
      tss = list(tickets.subsets(size=6))
      
      # possible counter displays
      def display(cs, ss=multiset()):
        if not cs:
          yield ss
        else:
          # choose the next key
          (a, b) = k = cs.peek()
          n = cs[k]
          # and choose the split (how many showing a, the rest show b)
          for x in irange(0, n):
            # remaining counters
            cs_ = cs.copy().remove(k, n)
            ss_ = ss.copy().update_from_pairs([(a, x), (b, n - x)])
            yield from display(cs_, ss_)
      
      # check this set of counters
      def check(cs, ts):
        # consider each possible display
        for x in display(cs):
          # remove ticket sequences with at least 5 matches
          ts = list(t for t in ts if len(x.intersection(t)) < 5)
          if not ts: return True
        return False
      
      # fake a counter by incrementing one side
      def fake1(x, y):
        yield (x, y + 1)
        if x < y: yield (x + 1, y)
      
      # fake a set of counters
      def fake(cs):
        # choose 2 counters
        for (a, b) in subsets(cs, size=2, select="mC"):
          # fake them
          for (fa, fb) in product(fake1(*a), fake1(*b)):
            # replace the originals with the fakes
            yield update(cs, rem=(a, b), add=(fa, fb))
      
      # consider possible counters
      for cs in mpartitions(tickets, 2):
        # check these counters can match at least 5 of all tickets sequences
        if not check(cs, tss): continue
        printf("counters = {cs}", cs=sorted(cs))
      
        # make the fake set of counters
        for fcs in fake(cs):
          # there should be 3 counters the same
          if all(v < 3 for v in fcs.values()): continue
          printf("-> faked = {fcs}", fcs=sorted(fcs))
      
          # choose 2 counters to match the calls "1" and "2"
          for (x, y) in subsets(fcs, size=2, select="mP"):
            if not (1 in x and 2 in y): continue
            # remaining counters
            rs = update(fcs, rem=(x, y))
            # is there a call that cannot be matched?
            if len(union(rs.keys())) == 4: continue
      
            # output solution (rs)
            printf("-> remaining = {rs}; [1 -> {x}, 2 -> {y}]", rs=sorted(rs))
            printf()
      

      Solution: The four remaining counters are: 2|4, 2|4, 2|4, 3|4.


      There is only one set of counters that meets the specified conditions:

      1|2, 1|3, 1|4, 2|3, 2|4, 3|4

      These are then faked by incrementing the 3rd and 4th counters to give:

      1|2, 1|3, 2|4, 2|4, 2|4, 3|4

      Which has 3 copies of the 2|4 counter.

      For the call of “1” the 1|3 counter is chosen. For the call of “2” the 1|2 counter is chosen.

      This leaves: 2|4, 2|4, 2|4, 3|4, which cannot match a call of “1”.

      Like

    • Frits's avatar

      Frits 12:10 pm on 21 June 2022 Permalink | Reply

      A lot easier to solve without using Python.

         
      # Suppose numbers in Ali's bag are a, b, c and d
      
      # ------ Check Baba's original set of counters -----------------
      # Can one counter have the same numbers on it?
      
      # Then fi we have counters a/a and a/x where x is b, c or d.
      # If Ali calls 3 a's and 3 x's then both his third a call and third x call 
      # can't be filled.   ===> each counter has 2 different numbers on it
      
      # Can 2 counters be the same?
      # Then fi we have counters a/b and a/b.
      # If Ali calls 3 a's followed by 3 b's then the last two b calls can't be
      # filled.   ===> no counter combination occurs more than once.
      
      # So Baba has to have 1/2, 1/3 and 1/4. He also needs to have 2/3 and 2/4
      # and finally 3/4.
      
      # so we have 1|2, 1|3, 1|4, 2|3, 2|4 and 3|4
      # --------------------------------------------------------------
      
      
      # In two counters a number is incremented by one, resulting in at least 
      # 3 counters with the same numbers x and y. This means the x|y counter must 
      # have been present in Baba's original set of counters.
      # x|y cannot be a counter like 1|z as there is only one option 1|(z-1) to 
      # produce an additional 1|z counter.   ===> 1|2, 1|3 and 1|4 are not x|y
      
      # x|y cannot be a counter like z|(z + 1) as there is only one option 
      # (z-1)|(z+1) to produce an additional z|(z + 1) counter.
      # ==> 2|3 and 3|4 are not x|y
      
      # so x|y is 2|4 and Baba's faked set being 1|2, 1|3, 2|4, 2|4, 2|4 and 3|4.
      # As Ali has called “Two” and “One” resp. 1|2 and 1|3 must have been placed
      # in a square.   ===> the four remaining counters are 2|4, 2|4, 2|4 and 3|4
      

      Like

  • Unknown's avatar

    Jim Randell 11:20 am on 15 May 2022 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 45: Ben’s big ‘uns 

    From The Sunday Times, 28th January 1962 [link]

    The high spot of the Appleton Harvest Home Fête was the sheep pen building match against the neighbouring village of Beescomb. The test was to build a rectangular pen of 500 ft. perimeter, all hurdles edge to edge and firm.

    Farmer Bull provided the hurdles, mainly standard six-footers, with a sprinkling of odd lengths, seven-foot and four-foot.

    Each crew captain chose the hurdles he required and had them stacked ready on the site. The stack of Albert, the Appleton captain, contained twice as many standard as odd length hurdles, while Ben of Beescomb (big ‘uns be best) had limited his odd lengths to quarter of the total.

    Twenty yards from the stacks the crews lined up. The whistle blew, the crowd roared and the rivals flew forward. So evenly were they matched that each averaged ten seconds to fix a seven-footer, eight for a six-footer and six for a four-footer.

    Amid yells of triumph, the winners banged down the last six-foot hurdle into the last six-foot gap.

    Who won, and by how many hurdles?

    [teaser45]

     
    • Jim Randell's avatar

      Jim Randell 11:20 am on 15 May 2022 Permalink | Reply

      This Python program uses the [[ express() ]] function from the enigma.py library to break the 500ft perimeter down into hurdles of the appropriate lengths, and looks for those with the required “standard” to “odd” ratio.

      It runs in 61ms. (Internal runtime is 3.1ms).

      Run: [ @replit ]

      from enigma import (express, div, product, printf)
      
      # fence panels available
      panels = (4, 6, 7)
      
      # time for a combination of panels
      time = lambda ns, ts=(6, 8, 10): sum(x * y for (x, y) in zip(ns, ts))
      
      # find possible stacks of panels for A and B
      (As, Bs) = (list(), list())
      
      # consider possible breakdowns of 500
      for (n4, n6, n7) in express(500, panels):
        # calculate "standard" to "odd" ratio
        d = div(n6, n4 + n7)
        if d is None: continue
        if d == 2:
          As.append((n4, n6, n7))
        elif d == 3:
          Bs.append((n4, n6, n7))
      
      # run the competition
      for (A, B) in product(As, Bs):
        (a, b) = (time(A), time(B))
        printf("A={A} vs B={B} = {a} vs {b}")
      

      Solution: Beescomb won by 1 hurdle.

      The program finds there is only one possible breakdown of hurdles for each team with the required ratio:

      A: 17× 4ft + 58× 6ft + 12× 7ft = 500ft; time = 686s
      B: 60× 6ft + 20× 7ft = 500ft; time = 680s

      So B wins by 6s (the time taken for A to place their final 4ft hurdle).

      The program doesn’t check that these can be broken down to make the sides of a rectangular pen, but there are many ways that this can be done. For example:

      A: 102ft × 148ft; 102ft = 17× 6ft (×2); 148ft = 16× 4ft + 12× 7ft, 1× 4ft + 24× 6ft
      B: 70ft × 180ft; 70ft = 10× 7ft (×2); 180ft = 30× 6ft (×2)

      Like

  • Unknown's avatar

    Jim Randell 10:47 am on 26 September 2021 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser: Silver collection 

    From The Sunday Times, 31st July 1960 [link]

    Seven South Sea Island brothers found on the beach a broken box and mixed silver coins scattered. These were old British coins (six-pence, shilling, florin, half-crown, and crown). 135 of them bore a man’s head and 54 a woman’s. The two younger brothers claimed the latter and their elders shared the former.

    Being ignorant of the value of the coins they agreed to take twenty-seven each. First they laid the coins in heaps of each size. The senior brother then took seven coins from each of two heaps and smaller numbers from the other three heaps to make up twenty-seven coins. Each other brother then took the same numbers but each from a different order of heaps.

    Unknown to themselves, the five elders had equal money value. The boys also had equal value, but greater than their elders.

    What were the values?

    [Note: Respective values: 6d, 12d, 24d, 30d, 60d]

    This is one of the occasional Holiday Brain-Teasers published in The Sunday Times prior to the start of numbered Teasers in 1961. A prize of 3 guineas was offered.

    This puzzle is included in the book Sunday Times Brain Teasers (1974). The above text is taken from the book.

    [teaser-1960-07-31] [teaser-unnumbered]

     
    • Jim Randell's avatar

      Jim Randell 10:49 am on 26 September 2021 Permalink | Reply

      This Python program runs in 51ms.

      Run: [ @replit ]

      from enigma import (decompose, group, subsets, printf)
      
      # denominations of coins
      denominations = [6, 12, 24, 30, 60]
      
      # total for quantities of coins in qs (wrt denominations)
      total = lambda qs: sum(x * y for (x, y) in zip(qs, denominations))
      
      # decompose 27 - 14 = 13 into 3 numbers between 1 and 6
      for qs in decompose(13, 3, min_v=1, max_v=6, sep=0):
        qs += (7, 7)
      
        # collect permutations by total amount
        d = group(subsets(qs, size=len, select="mP"), by=total)
      
        # look for 5 permutations for the elders
        for (k1, vs1) in d.items():
          if not (len(vs1) > 4): continue
          # and 2 permutations, with a greater sum for the youngers
          for (k2, vs2) in d.items():
            if not (k2 > k1 and len(vs2) > 1): continue 
            printf("elders = {k1} [from {vs1}]")
            printf("youngers = {k2} [from {vs2}]")
            printf()
      

      Solution: The elders had selected coins with a value of 798d (= 66s 6d). The youngers had selected coins with a value of 834d (= 69s 6d).

      Like

    • Hugh Casement's avatar

      Hugh Casement 3:13 pm on 26 September 2021 Permalink | Reply

      I confess I cheated by working backward from Jim’s solution, but was able to deduce that there were 48 crowns, 44 half crowns, 38 florins, 32 shillings, and 27 sixpences.
      Total 189 coins with a value £23 11s 6d = 5658 d.

      If the five piles were arranged in order of decreasing value, the seniors (in some order) took
      7, 7, 4, 3, 6; 7, 7, 3, 6, 4; 7, 6, 4, 7, 3; 7, 4, 7, 6, 3; 6, 7, 7, 3, 4 coins from the respective piles.
      The youngsters took 7, 7, 6, 3, 4 and 7, 6, 7, 4, 3.

      There would be other ways of making up the values 798 and 834 with 27 coins, but not with as many as five of one and two of the other, using the same numbers in different orders.

      Like

  • Unknown's avatar

    Jim Randell 10:28 am on 27 June 2021 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 37: Which page? 

    From The Sunday Times, 3rd December 1961 [link]

    A student desiring to find a reference in a book, could not remember the actual page number, but only the three figures comprising it.

    Before beginning his search, he wrote down in ascending order the six possible variants of the three figures. In writing the second variant his pencil broke on
    a figure which thereafter was illegible. With a fresh pencil he completed the list of variants and then found his reference, the page number being the second variant.

    Some time later he found in his pocket the scrap of paper bearing the six numbers. Idly adding them he obtained a total of 4,796, having unwittingly misread the illegible figure.

    On what page was the reference?

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

    This puzzle was originally published with no title.

    [teaser37]

     
    • Jim Randell's avatar

      Jim Randell 10:29 am on 27 June 2021 Permalink | Reply

      If he had written out each of the 6 numbers correctly (the digits being a, b, c), then each digit would appear twice in each position so the total sum of the six numbers would be:

      T = 222×(a + b + c)

      If the misinterpreted digit is off by x then the total sum is off by 100x if the first digit of the number is misinterpreted, 10x if its the second digit, and x if its the final digit.

      This Python program runs in 49ms.

      Run: [ @replit ]

      from enigma import (irange, subsets, div, nconcat, printf)
      
      M = 4796  # mistaken total
      
      # check to see if "abc" can be misread by d
      def check(a, b, c, d):
        # error in hundreds position? (a)
        x = div(abs(d), 100)
        if x:
          return 0 < (a + x if d > 0 else a - x) < 10
        # error in tens position? (b)
        x = div(abs(d), 10)
        if x:
          return 0 < (b + x if d > 0 else b - x) < 10
        # error in units position? (c)
        return 0 < (c + d) < 10
      
      # consider possible digits in the number
      for (a, b, c) in subsets(irange(1, 9), size=3):
        # the total sum should be...
        T = 222 * (a + b + c)
        # and the difference from the calculated sum
        d = M - T
        # digits of the 2nd number in the list are a, c, b
        if d != 0 and check(a, c, b, d):
          n = nconcat(a, c, b)
          printf("reference = {n} [read as {m}]", m=n + d)
      

      Solution: The reference was on page 198.

      So the sum of the numbers should have been 3996, but the second number was read as 998, adding 800 to the sum.

      Like

      • Frits's avatar

        Frits 10:22 am on 12 August 2025 Permalink | Reply

        from enigma import SubstitutedExpression  
        
        M = 4796  # mistaken total
        vars = "ABC"
        
        # i * j = difference with respect to the correct number 
        for i in range(-9, 10):
          if not i: continue
          for k, j in enumerate([100, 10, 1]):
            t, r = divmod(M - i * j, 222)
            if r: continue
            sum_ABC = str((M - i * j) // 222)
            # illegible figure may also have been a zero if idly adding them
            extra = "0 <= " + vars[k] + " + " + str(i) + " < 10"
            # digits of the 2nd number in the list are a, c, b
            p1 = SubstitutedExpression(["C < B", sum_ABC + " - B - C = A", 
                                        extra, "A < C"],
                                       answer="ABC", 
                                       digits=range(1, 10),
                                       reorder=0, 
                                       verbose=0)
            
            # solve the first alphametic
            for ans in p1.answers():
              print("answer:", ans)
        

        Like

  • Unknown's avatar

    Jim Randell 8:17 am on 18 April 2021 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 31: [Birthday weddings] 

    From The Sunday Times, 22nd October 1961 [link]

    Jane said:

    My mother and I were each married on our birthday and each at the same age. I was born four years and a day after my mother’s marriage, and my twins were born four years and a day after my marriage to John, who is three years older than I am, and who shares a birthday with my mother.

    If you write a date, say Christmas Day this year, in a continuous line of figures it looks like this – 25121961. Very well, if you write down our five dates of birth in that way and add the resultant numbers, the total is 8829685.

    When was her wedding day?

    This puzzle was originally published with no title.

    [teaser31]

     
    • Jim Randell's avatar

      Jim Randell 8:18 am on 18 April 2021 Permalink | Reply

      I was wondering when exactly “a year and a day” after 29th February was. It’s probably easiest to imagine there is a zero length 29th February in non-leap years, and then it is easier to calculate these “year and a day” offsets. In the analysis it turns out there is only one possible set of dates anyway.

      Assuming the 5 years of birth are all before 2000, we see that their sum must be a 4-digit number, i.e. 9685. And there is no carry into the sum of the day and month digits, which are 882. So we can deal this these three columns separately.

      As there are 5 birthdays they cannot all be in the same month (as the final digit of the day/month sum would end in 5 or 0). In order for the final digit to be 2, twins birthday must at the beginning of a month, Jane at the end of the previous month, and John and Mum the day before that.

      So the twins could be born on:

      1st Mar: sum = 13 + 13 + 282 + 272 + 272 = 852 (non leap-year)
      1st Mar: sum = 13 + 13 + 292 + 282 + 282 = 882 (leap year)
      1st May: sum = 15 + 15 + 304 + 294 + 294 = 922
      1st Jul: sum = 17 + 17 + 306 + 296 + 296 = 932
      1st Sep: sum = 19 + 19 + 318 + 308 + 308 = 972
      1st Oct: sum = 111 + 111 + 3110 + 3010 + 3010 = 9352

      And only 1st Mar (twins), preceded by 29th Feb (Jane), and 28th Feb (John, Mum), gives the sum 882.

      If the twins were born (on 1st Mar) in year y, then the year of Jane’s marriage is 4 years and 1 day earlier. And Jane is married on her birthday, which is 29th Feb, so (y − 4) (and hence y) must be a leap year.

      If Jane is married at age x years, then her birth date must be (y − x − 4) (also a leap year, so x must be a multiple of 4).

      And John is born on 28th Feb, 3 years earlier, i.e. in year (y − x − 7).

      Jane’s Mum was married exactly 1 year before that, i.e. in year (y − x − 8).

      So she was born in year: (y − 2x − 8).

      And the sum of the 5 birth years is 9685:

      2y + (y − x − 4) + (y − x − 7) + (y − 2x − 8) = 9685
      5y − 4x − 19 = 9685
      x = (5y − 9704) / 4

      Looking at leap years, going backwards from 1960:

      y = 1960: x = 24
      y = 1956: x = 19
      y = 1952: x = 14

      So the only viable candidate for (y, x) is (1960, 24) (as x must be a multiple of 4).

      So the dates we are interested in are:

      1960-03-01 = twins born
      1956-02-29 = Jane and John’s wedding; Jane’s 24th birthday
      1932-02-29 = Jane born
      1929-02-28 = John born
      1928-02-28 = Jane’s Mum’s wedding; Mum’s 24th birthday
      1904-02-28 = Jane’s Mum born

      Adding the 5 birth dates converted to integers we get:

      131960 + 131960 + 2921932 + 2821929 + 2821904 = 8829685

      Solution: Jane’s wedding day was: 29th February 1956.

      Like

  • Unknown's avatar

    Jim Randell 9:58 pm on 16 September 2019 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 500: [Succession] 

    From The Sunday Times, 3rd January 1971 [link]

    Joybells rang, fireworks went bang, and merry Bahreinis sang, celebrating not only their 500th Founding Festival, but also the coronation of the new monarch of Bahrein Teza.

    “But”, said our special correspondent, intercepting the Lord High Solutioner as he was hurrying through the Palace gates, “I understand there has been a disturbance concerning rival claimants to the throne?”

    “Yes, yes. A bit of bother. Long story”, replied the LHS. “Afraid I can’t stop now though. Banquet just starting. See you later. Wait! Here’s a copy of the royal genealogical tree. Tells you everything. Succession laws same as your own. Right?”, and he disappeared into the Palace.

    Well, here’s a relevant extract:

    CALCULUS – Son-in-law of NUMERA
    DATA III – Daughter of LOGICUS XI
    DATA – Mother of RIDELLA IV
    DECIMUS – Husband of PUZELA
    LOGICUS X – Father of NUMERA
    LOGICUS XI – Father of RIDELLA IV
    LOGICUS – Son of LOGICUS XI
    MATHUS – Brother-in-law of PUZLUS V
    NUMERA – Aunt of PUZLUS VI
    PUZELA – Cousin of LOGICUS XI
    PUZELA – Daughter-in-law of PUZELA
    PUZLUS V – Father of RIDELLA
    PUZLUS VI – Elder son of PUZLUS V
    RIDELLA IV – Niece of PUZLUS VI
    RIDELLA – Mother of SOLVUS II
    RIDELLA – Wife of LOGICUS XI
    SOLVUS II – Cousin of RIDELLA IV

    So who is crowned and who is the claimant?

    The following was published alongside this puzzle:

    Brain-teased 500 times

    “Tantalising but irresistible” sums up the reaction of thousands of readers to The Sunday Times Brain-teaser, which this week reaches its 500th example since numbering began on February 26, 1961.

    Competitors, from emeritus professors of mathematics to 11-year-olds, with a growing proportion of women, submit their solutions from every county and from 56 oversea States, some never having missed a week. It is calculated that between 40,000/50,000 readers send a solution every year.

    Set by Sunday Times readers, the problems are selected from about 200 a year, vetted for uniqueness of solutions by independent experts (with an occasional oversight) and are published in varying degrees of difficulty; entries then range weekly from around 4,000 to a handful from the master-minds.

    Anthony French

    This puzzle was originally published with no title.

    [teaser500]

     
    • Jim Randell's avatar

      Jim Randell 9:59 pm on 16 September 2019 Permalink | Reply

      For me this puzzle isn’t well enough defined.

      For instance:

      PUZELA − Daughter-in-law of PUZELA

      Does this mean that PUZELA married her own son? Or is there not a one-to-one correspondence between names and people?

      Maybe each line of the genealogy refers to a different person? If so, there are two PUZELAs and RIDELLAs and we don’t know which is referred to when the names are used again.

      And even if you come up with an answer there seems to be no way to check if it is right.

      However, as I have transcribed the puzzle (and at least glanced at it) I am posting it for completeness, and in case someone else is interested in it.


      The published solution is:

      Crowned = DECIMUS. Claimant = LOGICUS.

      A splendid baffling problem of succession. Did no one spot the Stuart parallel? A mixed bag. 18% right.

      So it doesn’t look like it was that well received at the time.

      Like

    • Lise Andreasen's avatar

      Lise Andreasen 6:26 am on 28 July 2024 Permalink | Reply

      Yeah. Can’t quite make sense of it.

      Like

  • Unknown's avatar

    Jim Randell 11:16 am on 5 March 2019 Permalink | Reply
    Tags: by: C Skeffington Quin   

    Brain-Teaser 460: [Crates of Boppo] 

    From The Sunday Times, 22nd March 1970 [link]

    Boppo is made up in 1 lb cans at 8s, 2 lb cans at 15s and 4 lb cans at 27s. The contents of crates vary, but every crate contains 60 cans of mixed three sizes with a total value of £45.

    The foreman himself had packed two such crates. He told new worker Rob, “Just go along and nail down those two open crates in the shed, Rob. The lorry’s waiting.”

    Rob found the two crates standing beside the weighing platform, and for no particular reason he weighed them. One was heavier than the other. “Huh! Calls ‘isself a foreman” he said, as he removed some cans from the heavier crate. “That’s it. Both the same now. Lucky I weighed ’em”. So he nailed them down and the lorry went off with them.

    He met the foreman. “You made a mistake with those crates, chum”, he said, “but it’s OK now. Here’s three spare cans.”

    “!!” said the foreman.

    What were the weights of the two crates the foreman had packed?

    This puzzle was originally published with no title.

    [teaser460]

     
    • Jim Randell's avatar

      Jim Randell 11:19 am on 5 March 2019 Permalink | Reply

      Before decimalisation £1 was the same as 20 shillings, so each crate has a monetary value of 900 shillings.

      I solved this using a similar approach to Enigma 486 (and borrowed some of the code too).

      This Python 3 program runs in 108ms.

      from enigma import (defaultdict, irange, subsets, printf)
      
      # express total <t> using denominations <ds>, min quantity 1
      def express(t, ds, s=[]):
        if not ds:
          if t == 0:
            yield s
        else:
          (d, *ds) = ds
          for i in irange(1, t // d):
            yield from express(t - d * i, ds, s + [i])
      
      # the weights and costs of the cans
      weights = (1, 2, 4)
      costs = (8, 15, 27)
      
      # find ways to split the cost of a crate into cans
      crates = defaultdict(list)
      for ns in express(900, costs):
        # but each crate has 60 cans
        if not (sum(ns) == 60): continue
        # calculate the total weight of the crate
        t = sum(n * w for (n, w) in zip(ns, weights))
        printf("[{ns} -> weight = {t}]")
        crates[t].append(ns)
      
      # possible weights of 3 cans to be removed
      w3s = defaultdict(list)
      for rs in subsets(weights, size=3, select='R'):
        w3s[sum(rs)].append(rs)
      
      # find two crates with weights that differ by 3 cans
      for (w1, w2) in subsets(sorted(crates.keys()), size=2):
        for rs in w3s[w2 - w1]:
          # check there are enough cans in the w2 crate
          if not any(all(not (r > n) for (r, n) in zip(rs, ns)) for ns in crates[w2]): continue
          # output solution
          printf("{w2} lb -> {w1} lb by removing {rs} x {weights} lb cans")
      

      Solution: The crates the foreman had packed weighed 122 lb and 126 lb.

      Rob reduced the weight of the 126 lb crate to 122 lb by removing 2× 1 lb cans and 1× 2 lb can.

      There are only 3 ways to pack the crates so they have 60 cans and are worth 900 shillings (900s) (where the is at least 1 of each type of can included):

      12× 1 lb @ 8s + 41× 2 lb @ 15s + 7× 4 lb @ 27s = 60 cans, 122 lb, 900s
      24× 1 lb @ 8s + 22× 2 lb @ 15s + 14× 4 lb @ 27s = 60 cans, 124 lb, 900s
      36× 1 lb @ 8s + 3× 2 lb @ 15s + 21× 4 lb @ 27s = 60 cans, 126 lb, 900s

      If we don’t require that all three weights of can are represented in the crate then we can make a crate with 60× 2 lb cans, which weighs 120 lb, and gives rise to multiple solutions.

      Like

    • GeoffR's avatar

      GeoffR 7:42 am on 6 March 2019 Permalink | Reply

      The only 3 ways to pack a crate are found in my MiniZinc programme as 122 lb, 124 lb and 126 lb

      The only way of removing 3 cans to make the crates equal is to remove 3 cans ( 2 of 1lb and 1 of 2lb = 4lb) to reduce the crate weighing 126 ilb to 122 lb.

      Therefore, the foreman had packed 122 lb and 126 lb into the two crates.

      var 1..60: n1; var 1..60: n2;  var 1..60: n3;   % Numbers of  three types of can
      var 1..200: wt;   %total weight of all cans in 1 crate
      
      constraint n1 + n2 + n3 == 60;  % Every crate contains 60 cans
      constraint n1 * 8 + n2 * 15 + n3 * 27 == 900;   %sh £45 * 20 = 900 shillings for 1 crate
      constraint wt = n1 * 1 + n2 * 2 + n3 * 4;
      
      solve satisfy;
      
      % n1 = 12;  n2 = 41;  n3 = 7;  wt = 122;
      %----------
      % n1 = 24;  n2 = 22;  n3 = 14;  wt = 124;
      % ----------
      % n1 = 36;  n2 = 3;  n3 = 21;  wt = 126;
      %----------
      %==========
      %Finished in 199msec
      
      

      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

Why are you reporting this comment?

Report type
Design a site like this with WordPress.com
Get started