Updates from Jim Randell Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 8:16 am on 25 April 2019 Permalink | Reply
    Tags:   

    Brainteaser 1563: Family sum 

    From The Sunday Times, 23rd August 1992 [link]

    In this puzzle digits have been consistently replaced by letters, with different letters being used for different digits. This addition sum then makes sense:

    also AND is divisible by three.

    What is the number REAGAN?

    This puzzle is included in the book Brainteasers (2002). The wording is only slightly changed from the original puzzle.

    [teaser1563]

     
    • Jim Randell's avatar

      Jim Randell 8:17 am on 25 April 2019 Permalink | Reply

      This puzzle can easily be solved using the [[ SubstitutedExpression() ]] solver from the enigma.py library.

      The following run-file executes in 480ms.

      Run: [ @replit ]

      #! python3 -m enigma -rr
      
      SubstitutedExpression
      
      "RONALD + AND + NANCY = REAGAN"
      
      "AND % 3 = 0"
      
      --answer="REAGAN"
      

      Solution: REAGAN = 396168.

      The symbols L and C appear in the tens column, but not elsewhere, so their values can be interchanged. This gives rise to the two possible sums:

      308627 + 687 + 86854 = 396168
      308657 + 687 + 86824 = 396168

      Like

      • Jim Randell's avatar

        Jim Randell 8:41 am on 9 June 2023 Permalink | Reply

        For a faster solution we can use the [[ SubstitutedExpression.split_sum ]] solver.

        The following run file executes in 73ms. (Internal runtime of the generated program is 1.5ms).

        Run: [ @replit ]

        #! python3 -m enigma -rr
        
        SubstitutedExpression.split_sum
        
        "RONALD + AND + NANCY = REAGAN"
        
        --extra="AND % 3 = 0"
        
        --answer="REAGAN"
        

        Like

    • GeoffR's avatar

      GeoffR 12:20 pm on 25 April 2019 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
       
      var 0..9: R; var 0..9: O; var 0..9: N; var 0..9: A;  var 0..9: L; 
      var 0..9: D; var 0..9: C; var 0..9: Y; var 0..9: E;  var 0..9: G; 
      
      constraint R != 0 /\ A != 0 /\ N != 0;
      constraint all_different( [R,O,N,A,L,D,C,Y,E,G]);
      
      var 100..999: AND = 100*A + 10*N + D;
      var 10000..99999: NANCY = 10000*N + 1000*A + 100*N + 10*C + Y;
      
      var 100000..999999: RONALD = 100000*R + 10000*O + 1000*N 
      + 100*A + 10*L + D;
      
      var 100000..999999: REAGAN = 100000*R + 10000*E + 1000*A 
      + 100*G + 10*A + N;
      
      constraint AND mod 3 == 0;
      
      constraint RONALD + AND + NANCY == REAGAN;
      
      solve satisfy;
      
      output [show(RONALD) ++ " + " ++ show(AND) ++ " + " ++ 
      show(NANCY) ++ " = " ++ show(REAGAN)];
      
      % 308657 + 687 + 86824 = 396168
      % time elapsed: 0.02 s
      % ----------
      % 308627 + 687 + 86854 = 396168
      % time elapsed: 0.02 s
      %----------
      %==========
      
      

      Like

    • Frits's avatar

      Frits 1:44 pm on 9 June 2023 Permalink | Reply

        
      column 3: x + N + A = .A with x = 1,2,3 so N = 8,9,0
      
      column 2: y + O + N = E so either:
      
      N = 9, is not possible
      N = 8 and O = 0 and x = 2  
      N = 0 causes y to be zero but then O = E
      
      --> N = 8, O = 0, E = 9 and x = 2
      
      column 4:
      z + A + A + N = 2G so z + A + A >= 21 - 8 so A = 6,7
      
      using AND is divisible by three:
      (A, D, Y) is either (6, 7, 4) or (7, 3, 2)
      (A, D, Y, L+C) is either (6, 7, 4, 7) or (7, 3, 2, 9)
      (A, D, Y, {L, C}) is either (6, 7, 4, {2, 5}) or (7, 3, 2, {4, 5})
      
      (A, G) = (6, 1) as A = 7 causes G to be 3 (which is same as D)
      
      so (N, O, E, A, D, Y, G) = (8, 0, 9, 6, 7, 4, 1) with {L, C} = {2, 5}
      This leaves R = 3
      

      Like

  • Unknown's avatar

    Jim Randell 10:47 am on 24 April 2019 Permalink | Reply
    Tags:   

    Teaser 2920: Barcode 

    From The Sunday Times, 9th September 2018 [link] [link]

    When Fred opened his “10 to 99 Store” (the numbers reflecting the prices of the goods in pounds) there was trouble from the start when the barcode reader scanned the prices backwards. First at the self-service checkout was Mrs Adams, who kept quiet when she was charged £59.49 for a £94.95 item. The next two customers, Mr Baker and Mr Coles, paid by card, without noticing they had in fact been overcharged. All three had bought a differently-priced item, and by coincidence, in the case of the two men, the price each had been charged was a whole multiple of the actual price.

    How much had the shop lost or gained overall on the three transactions?

    [teaser2920]

     
    • Jim Randell's avatar

      Jim Randell 10:48 am on 24 April 2019 Permalink | Reply

      This Python program runs in 157ms.

      (The following is for Python 2.7, see the code on repl.it for the Python 3 version).

      Run: [ @repl.it ]

      from enigma import (Accumulator, irange, nreverse, div, printf)
      
      # r accumulates the total gain for the shop
      def transaction(t, (p, q)):
        d = q - p
        printf("[{n}: price = {p} -> charged = {q}, diff = {d}]", n=r.count)
        return t + d
      
      r = Accumulator(fn=transaction, value=0)
      
      # transaction A
      p = 9495
      q = nreverse(p)
      assert q < p
      r.accumulate((p, q))
      
      # for transactions B and C, consider 4-digit prices
      for p in irange(1000, 9999):
        # reverse the price
        q = nreverse(p)
        if not (q > p): continue
        # reversed price is an exact multiple
        m = div(q, p)
        if m is None or m < 2: continue
        r.accumulate((p, q))
      
      # there should be three transactions in total
      assert r.count == 3
      
      # output total
      printf("total shop gain = {g:.2f} pounds", g=r.value * 0.01)
      

      Solution: In total the shop gained £ 117.00 over the three transactions.

      The transactions for B and C are:

      (1) paying £ 98.01 for an item priced at £ 10.89 (9 times)
      (2) paying £ 87.12 for an item priced at £ 21.78 (4 times)

      Like

  • Unknown's avatar

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

    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 9:21 am on 22 April 2019 Permalink | Reply
    Tags:   

    Teaser 2921: Octavia the octagonarian 

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

    Queen Octavia’s emblem was two concentric regular octagons (the outermost’s side length equal to the innermost’s distance between opposite sides). Seen from above her eightieth-birthday, level, cheesecake torte, with octagonal cavity all the way through and vertical side-faces, matched the emblem. Its outer side-faces were square and a two-figure whole number of inches wide. A four-feet diameter cylindrical cover protected it. At the party the whole torte was used, without wastage, to levelly fill a number of identical cuboid dishes (internally having length, width and depth, in inches, each a different single-figure whole number greater than one). Curiously, the number of dishes was a three-figure value with different numerals in descending order.

    What was the torte’s volume in cubic inches?

    [teaser2921]

     
    • Jim Randell's avatar

      Jim Randell 9:22 am on 22 April 2019 Permalink | Reply

      This Python program runs in 78ms.

      Run: [ @repl.it ]

      from enigma import (irange, subsets, nsplit, tuples, sqrt, intf, div, printf)
      
      # diameter of a regular octagon with side 1 unit
      d = sqrt(4 + 2 * sqrt(2))
      
      # possible volumes of the dishes
      vs = set(a * b * c for (a, b, c) in subsets(irange(2, 9), size=3))
      
      # is <n> a k-digit descending number?
      def check(n, k=3):
        ds = nsplit(n)
        return (len(ds) == k and all(a > b for (a, b) in tuples(ds, 2)))
      
      # consider <x>, the side length of the outer octagon = the distance
      # between opposite faces of the inner octagon
      # the outer octagon can fit in a 48 inch tube
      for x in irange(10, min(99, intf(48.0 / d))):
      
        # volume of cake
        V = 4 * x**3
      
        # consider the volume of each dish
        for v in vs:
      
          # the number of dishes is:
          n = div(V, v)
          if n is None or not check(n): continue
      
          printf("x={x} V={V}, v={v} n={n}")
      

      Solution: The volume of the torte was 23,328 cubic inches.

      The outside faces of the cake are 18 inch squares, and this is the largest cake that will fit inside a 48 inch diameter tube.

      There are 2 possibilities for the size of the serving dishes, either 972 dishes measuring 2×3×4 inches, or 432 dishes measuring 2×3×9 inches.

      Although the larger dish size has a number of dishes composed of consecutive descending digits (which is possibly what the setter had in mind), I think the smaller sized dish makes the most sense. Which means there were almost 1,000 guests catered for.

      Like

  • Unknown's avatar

    Jim Randell 12:51 pm on 21 April 2019 Permalink | Reply
    Tags:   

    Brainteaser 1557: An alphabetical jigsaw 

    From The Sunday Times, 12th July 1992 [link]

    I have some jigsaw pieces which fit together to form a 5-by-5 square with the letters all the right way up. Here is an attempt to make the jigsaw:

    The attempt has failed because the last piece does not fit the right way up. In fact it is possible to make the 5-by-5 jigsaw so that the 25 different letters spell six words in reading order.

    What is this arrangement?

    This puzzle appears in the book Brainteasers (2002). The wording above is taken from the book, but is only slightly changed from the original puzzle.

    [teaser1557]

     
    • Jim Randell's avatar

      Jim Randell 12:52 pm on 21 April 2019 Permalink | Reply

      There are two parts to the program. The first is concerned with fitting the pieces into the grid. The second part is then reading the letters in the grid as a collection of words.

      This Python program runs in 6.6s, but most of the time is taken up with collecting the word list. I used a collection of allowable Scrabble words, which gives 49,595 viable words.

      Run: [ @replit ] (using just the selected words)

      from itertools import product
      from collections import (Counter, defaultdict)
      from enigma import (irange, find, chunk, flatten, join, printf)
      
      (X, Y) = (1, 7)
      
      pieces = [
        { 0: 'H', Y: 'Z', X + Y: 'F', X + Y + Y: 'X' },
        { 0: 'P', X: 'S', X + X: 'C' },
        { 0: 'I', Y: 'J', Y + Y: 'O' },
        { 0: 'G', X: 'Y', X + Y: 'M' },
        { 0: 'T', Y: 'V', Y + Y: 'N' },
        { 0: 'E', Y: 'K', X + Y: 'W' },
        { 0: 'U', Y: 'R', X + Y: 'D' },
        { 0: 'A', X: 'L', X + Y: 'B' },
      ]
      
      # create the empty grid
      grid = [None] * (Y * Y)
      for (x, y) in product(irange(1, 5), irange(1, 5)):
        grid[x + y * Y] = '.'
      
      # fit piece p into grid g at index i
      # return new grid or None
      def fit(g, p, i):
        g = g.copy()
        for (k, v) in p.items():
          x = g[i + k]
          # non-usable square?
          if x != '.': return None
          g[i + k] = v
        return g
      
      def solve(ps=pieces, g=grid):
        # are we done?
        if not ps:
          # return the completed (unpadded) grid
          yield list(r[1:-1] for (i, r) in enumerate(chunk(g, Y), start=1) if 1 < i < Y)
        else:
          # find an empty square
          i = find(g, '.')
          if i != -1:
            for (j, p) in enumerate(ps):
              g2 = fit(g, p, i)
              if g2 is not None:
                yield from solve(ps[:j] + ps[j + 1:], g2)
      
      # list of words to examine
      file = "words.txt"
      
      # collect letters from the pieces
      letters = Counter()
      for p in pieces: letters.update(p.values())
      
      # collect words that can be formed from the letters
      words = defaultdict(list)
      for w in open(file).readlines():
        w = w.strip().upper()
        if not (Counter(w) - letters):
          words[w[0]].append(w)
      
      printf("[collected {n} words from {file}]", n=sum(len(v) for v in words.values()))
      
      # form text t into a sequence of words
      def check(t, s=[]):
        if not t:
          yield s
        else:
          for w in words[t[0]]:
            if t.startswith(w):
              yield from check(t[len(w):], s + [w])
      
      
      # fit the pieces into the grid
      for g in solve():
        # attempt to form the letters into words
        wss = list(check(join(flatten(g))))
        if wss:
          # output the grid
          for r in g:
            printf("{r}", r=join(r, sep=" "))
          # output the words
          for ws in wss:
            if len(ws) == 6:
              printf("words: {ws}", ws=join(ws, sep=", "))
          printf()
      

      Solution: The completed jigsaw looks like this:

      So the 6 words are: GYP, SCHMALTZ, FIB, VEX, JUNK, WORD.

      There are 64 ways to fit the pieces into the grid, but only one of them makes a set of viable words.

      There are 2 fifteen letter words in the list that can be made from the collection of letters in the puzzle: DERMATOGLYPHICS, UNCOPYRIGHTABLE.

      Like

  • Unknown's avatar

    Jim Randell 9:04 am on 20 April 2019 Permalink | Reply
    Tags: by: E C Parker   

    Brain-Teaser 474: [Triangular park] 

    From The Sunday Times, 28th June 1970 [link]

    Three friends live at the side entrances to a park bordered by three straight roads. Alan’s entrance is on the shortest road, Colin’s on the longest East to West road, and Brian’s on the road of mid length.

    Brian and Colin are directly North and South apart across the park, for half the distance they each are by road from Alan. The distance Brian and Colin are apart, plus the length of the three roads, is three miles.

    Each entrance is a number of exact yards by road, from any corner of the park, and Alan is as near to one corner as possible.

    How far from that corner is he?

    This puzzle was originally published with no title.

    [teaser474]

     
    • Jim Randell's avatar

      Jim Randell 9:06 am on 20 April 2019 Permalink | Reply

      If B and C’s gates are at a distance of d apart N-S across the park, and distances b and c from a corner X, then (b, c, d) form a Pythagorean triple.

      Once we have a suitable Pythagorean triple we can extend the lines XB and XC by lengths of 2d and bend them (at integer values) so that the bent sides form the third side of the triangle, which meet at A’s gate.

      If this is possible we have a viable solution. We then need to find which solution places A’s gate closest to a corner of the park.

      This Python program finds candidates solutions and choose the one with the smallest distance from A’s gate to a corner. It runs in 108ms.

      Run: [ @repl.it ]

      from enigma import (pythagorean_triples, irange, div, Accumulator, printf)
      
      # find the minimum distance of A from a corner
      r = Accumulator(fn=min)
      
      # BCX is right angled triangle with integer sides
      for (x, y, z) in pythagorean_triples(5280):
        for (b, c, d) in [(z, x, y), (z, y, x)]:
      
          # check 5d + b + c = 5280 yards
          if not (5 * d + b + c == 5280): continue
      
          # now consider possible integer values for y
          for y in irange(1, 2 * d - 1):
      
            # compute viable z (using the cosine rule)
            p = (b - c) * (b * b + b * (4 * d + c) + 4 * d * (c + 2 * d - y))
            q = 2 * (b * b + b * (2 * d + y) + c * (y - c - 2 * d))
            z = div(p, q)
            if z is None or not (0 < z < 2 * d): continue
      
            # compute the sides of the park
            (A, B, C) = (y + z, b + 2 * d - z, c + 2 * d - y)
      
            # A is on the shortest side and C is on the longest side
            if not (A < B < C): continue
      
            # additional: the park is a right angled triangle
            #if not (A * A + B * B == C * C): continue
      
            printf("[A={A} B={B} C={C}, d={d} b={b} c={c}, y={y} z={z}]")
      
            r.accumulate_data(min(y, z), (A, B, C, d, b, c, y, z))
      
      # output the solution
      printf("min distance for A from a corner = {r.value} yards [{r.count} solutions]")
      

      Solution: The shortest distance A’s gate can be from a corner is 135 yards.

      The program finds 8 possible solutions:

      A=1218 B=1400 C=2002, d=660 b=1100 c=880, y=198 z=1020
      A=1155 B=1540 C=1925, d=660 b=1100 c=880, y=275 z=880
      A=1122 B=1650 C=1848, d=660 b=1100 c=880, y=352 z=770
      A=1110 B=1750 C=1760, d=660 b=1100 c=880, y=440 z=670
      A=780 B=1800 C=2220, d=480 b=1480 c=1400, y=140 z=640
      A=750 B=1850 C=2200, d=480 b=1480 c=1400, y=160 z=590
      A=678 B=2050 C=2072, d=480 b=1480 c=1400, y=288 z=390
      A=429 B=2196 C=2325, d=330 b=1830 c=1800, y=135 z=294

      The last of these has the smallest value for y or z.

      So the park looks like this:


      However, apparently this was not the intended answer to this puzzle. The puzzle text should have said that the park was a right angled triangle, but this extra condition was omitted when the puzzle was published.

      We can remove solution candidates that are not right-angled triangles by uncommenting the check at line 29.

      If we do this we find that only one of the solutions remains:

      A=1155 B=1540 C=1925, d=660 b=1100 c=880, y=275 z=880

      The shortest distance being 275 yards.

      In this case the park looks like this:

      However, given there is only a single solution it seems odd to have the statement: “Alan is as near to one corner as possible”. It would make more sense to just ask: “How far is Alan from the nearest corner?”.

      Like

  • Unknown's avatar

    Jim Randell 8:29 pm on 19 April 2019 Permalink | Reply
    Tags:   

    Teaser 2922: Inscribed 

    From The Sunday Times, 23rd September 2018 [link]

    The Republic of Mathematica has an unusual rectangular flag. It measures 120 cm by 60 cm and has a red background. It features a green triangle and a white circle. All the lengths of the sides of the triangle and the radius of the circle (which touches all three sides of the triangle) are whole numbers of cm. Also, the distances from the vertices of the triangle to the centre of the circle are whole numbers of cm. The flag has a line of symmetry.

    What is the length of the shortest side of the triangle?

    [teaser2922]

     
    • Jim Randell's avatar

      Jim Randell 8:29 pm on 19 April 2019 Permalink | Reply

      The flag has a line of symmetry, so I supposed the triangle was isosceles, with sides a, a, b.

      If we split it in half down the middle we get a right-angled triangle, with base q = b/2, height h and hypotenuse a.

      The height h can be split into r the radius of the incircle (an integer) plus x the distance from the incentre to a vertex of the triangle (also an integer), so is itself an integer.

      (b/2)² = a² − h²

      The right hand side is the difference of two integers, so is an integer, and hence b/2 is an integer.

      So (q, h, a) is a Pythagorean triple.

      The inradius r can be calculated as the area of the isosceles triangle, divided by its semiperimeter.

      r = qh / (a + q)

      And this must be an integer.

      We can the calculate the distance y from the incentre to the lower vertices:

      y = hypot(q, r)

      And this also must be an integer, so (r, q, y) is also a Pythagorean triple.

      This Python program runs in 69ms.

      Run: [ @replit ]

      from enigma import (pythagorean_triples, div, is_square, arg, printf)
      
      # check a (q, h, a) pythagorean triangle (q = b/2)
      def check(q, h, a):
        # inradius = area / semiperimeter
        r = div(q * h, a + q)
        if r is None: return
        y = is_square(r * r + q * q)
        if y is None: return
        printf("a={a} b={b}, r={r}, x={x} y={y}", b=2 * q, x=h - r)
      
      # maximum length line in a 60 x 120 square is intf(hypot(60, 120)) = 134
      M = arg(134, 0, int)
      
      # consider pythagorean triples with hypotenuse up to M
      for (a, b, h) in pythagorean_triples(M):
        check(a, b, h)
        check(b, a, h)
      

      Solution: The shortest side of the triangle is 56 cm.

      The isosceles triangle has sides measuring 100 cm, 100 cm, 56 cm.

      The radius of the incircle is 21 cm. The upper vertex of the triangle is 75 cm from the incentre, the lower vertices are 35 cm from the incentre.

      Like

  • Unknown's avatar

    Jim Randell 8:31 am on 18 April 2019 Permalink | Reply
    Tags:   

    Brainteaser 1547: Doing the rounds 

    From The Sunday Times, 3rd May 1992 [link]

    This week, I share a find-the-next-row puzzle that is doing the rounds of dons’ whiteboards:

    1
    1 1
    2 1
    1 2 1 1
    ?

    To avoid invasion of ivory towers, I will give you the answer:

    1 1 1 2 2 1

    with the explanation that, starting with the initial 1, each subsequent row is obtained by reading the previous row. Thus, row five is formed (with reference to row four) from one “one”, followed by one “two”, and terminating with two “one”s.

    However, I do have four questions about the first billion rows of this sequence.

    1. What is the largest digit that can be found anywhere?
    2. What is the largest number of ones that can occur consecutively in any single row?
    3. Repeat (2), looking for twos instead.
    4. Repeat (2), looking for threes instead.

    Multiply each answer by its question number and send in the total.

    This puzzle is included in the book Brainteasers (2002), in which it appears in the following form:

    Read me!

    Consider the sequence:

    1
    11
    21
    1211
    111221
    312211

    You might like to try and work out the next few terms before reading on and trying the rest of this Teaser.

    In fact, having started with 1, each subsequent term simply reads the previous line. So, for example, after 111221 we note that this consists of:

    three ones, two twos, one one

    i.e. the next term is simply:

    312211

    Here are some questions about the first billion terms of this sequence:

    (a) What is the largest number of consecutive ones in any term?
    (b) What is the largest number of consecutive twos in any term?
    (c) What is the largest number of consecutive threes in any term?
    (d) What is the largest digit which can be found in any term?

    [teaser1547]

     
    • Jim Randell's avatar

      Jim Randell 8:33 am on 18 April 2019 Permalink | Reply

      This Python program generates the first few terms of the sequence. To do the first 12 terms takes 80ms.

      Run: [ @replit ]

      from enigma import (repeat, chunk, arg, printf)
      
      # transform the input sequence s, by counting the runs of digits
      def transform(s):
        r = list()
        while s:
          x = s[0]
          for (j, y) in enumerate(s):
            if j > 0 and y != x:
              r.extend([j, x])
              s = s[j:]
              break
          else:
            r.extend([j + 1, x])
            break
        return r
      
      # how many sequences to examine
      N = arg(12, 0, int)
      
      # record max runs (in the previous term)
      m = dict()
      
      # repeatedly apply the transform, starting with [1]
      for (i, s) in enumerate(repeat(transform, [1]), start=1):
        if N < 15: printf("({i}) -> {s}")
      
        # each transformed sequence consists of (n, d) pairs
        # telling us there were n runs of digit d in the previous term
        if i > 1:
          for (n, d) in chunk(s, 2):
            if n > m.get(d, 0):
              m[d] = n
      
        if not (i < N): break
      
      # output solutions
      for k in sorted(m.keys()):
        printf("digit {k} -> {n} times", n=m[k])
      printf("max digit = {k}")
      

      Together with some analysis we can now answer the questions:

      First we note that we can’t split runs of the same digit, so if we have (for example) five d‘s, …ddddd…., they will appear in the next sequence as …(5d)…, and not as …(2d)(3d)… etc.

      So in any transformed sequence we cannot have two pairs appearing consecutively for the same digit, i.e. …(xd)(yd)… would not appear, because it would be …({x+y}d)…

      So, we certainly cannot have a sequence of four consecutive digits …(dd)(dd)… appearing in a transformed sequence.

      But neither can we have …(xd)(dd)(dy)… appearing, as that also has two pairs appearing consecutively for the same digit.

      So we cannot have a run of more than three consecutive digits in any transformed sequence.

      Which means in any transformed sequence we will not see a digit greater than 3.

      Running the program we see that in the first 12 sequences we have three 1’s appearing in sequence 5:

      (5) → [1, 1, 1, 2, 2, 1]

      and three 2’s appearing in sequence 7:

      (7) → [1, 3, 1, 1, 2, 2, 2, 1]

      but we only manage two 3’s in sequence 11:

      (11) → [1, 1, 1, 3, 1, 2, 2, 1, 1, 3, 3, 1, 1, 2, 1, 3, 2, 1, 1, 3, 2, 1, 2, 2, 2, 1]

      And in fact we can see that it is not possible to achieve three 3’s.

      If we think about the first sequence in which …333… appears, then the digits must be paired as …(33)(3x)… (as …(x3)(33)… is not possible), but then the (33) indicates that the sequence before this one must have had a run of three 3’s (followed by three of another digit). But this is a contradiction. So we cannot find a first sequence with three 3’s.

      So that answer to puzzle from the book is:

      Solution: (a) 3; (b) 3; (c) 2; (d) 3.

      And solution for the original puzzle is: 1×3 + 2×3 + 3×3 + 4×2 = 26.

      To consider the first 40 sequences take my program 5.5s, and the 40th sequence has 63,138 digits, so it is not suitable for attempting to examine the first billion terms.

      The sequence is known as the “look and say” sequence [@wikipedia].

      Like

  • Unknown's avatar

    Jim Randell 12:55 pm on 17 April 2019 Permalink | Reply
    Tags:   

    Teaser 2923: Powerful numbers 

    From The Sunday Times, 30th September 2018 [link] [link]

    George and Martha’s five daughters have been investigating large powers of numbers. Each daughter told the parents that they had worked out a number which was equal to its last digit raised to an exact power. When Andrea announced her power, the parents had a 50% chance of guessing the last digit. When Bertha announced a larger power, the same applied. When Caroline announced her power, the parents had only a 25% chance of guessing the last digit; with Dorothy’s larger power, the same applied. When Elizabeth announced hers, the parents only had a 12.5% chance of guessing the last digit. I can tell you that the five powers were consecutive two-digit numbers adding up to a perfect square.

    What, in alphabetical order of the daughters, were the five powers?

    [teaser2923]

     
    • Jim Randell's avatar

      Jim Randell 12:55 pm on 17 April 2019 Permalink | Reply

      We ignore the digits 0 and 1 (as 0^k = 0 and 1^k = 1 for positive k), which leaves the digits 2 to 9.

      A chance of 50% is 1 out of 2, 25% is 1 out of 4, and 12.5% is 1 out of 8, so we are looking for a collection of consecutive numbers where 2 numbers have a choice from 2, another 2 have a choice from 4, and the remaining number has a choice from 8.

      This Python program looks at sequences of 5 consecutive 2-digit numbers, and when it finds one that sums to a square it checks that the choices for the digits conform to this pattern.

      It runs in 71ms.

      Run: [ @repl.it ]

      from enigma import (irange, tuples, is_square, icount, printf)
      
      # consider 5-sequences of consecutive 2-digit numbers for the powers
      for ks in tuples(irange(10, 99), 5):
        # the 5 powers sum to a square
        if is_square(sum(ks)) is None: continue
      
        # find the number of digits (ignoring 0 and 1) where d^k mod 10 = d
        ns = list(icount(irange(2, 9), (lambda d: pow(d, k, 10) == d)) for k in ks)
        if sorted(ns) != [2, 2, 4, 4, 8]: continue
      
        # extract indices for the given value
        indices = lambda v: (i for (i, n) in enumerate(ns) if n == v)
      
        # A has the first 2, B has the second 2
        (A, B) = indices(2)
        # C has the first 4, D has the second 4
        (C, D) = indices(4)
        # E has the 8
        (E,) = indices(8)
        
        printf("A={A} B={B} C={C} D={D} E={E}", A=ks[A], B=ks[B], C=ks[C], D=ks[D], E=ks[E])
      

      Solution: The five powers are: A=44, B=46, C=43, D=47, E=45.

      There are only three sequences that sum to a square:

      (18, 19, 20, 21, 22) → 10²
      (43, 44, 45, 46, 47) → 15²
      (78, 79, 80, 81, 82) → 20²

      And only one of these gives the right set of choices when raising the digits 2-9 to the corresponding powers.


      Analytically:

      If we consider digits d from 2 to 9, and look at increasing powers k such that d^k end in the digit d we get:

      k=1: d=2, 3, 4, 5, 6, 7, 8, 9
      k=2: d=5, 6
      k=3: d=4, 5, 6, 9
      k=4: d=5, 6
      k=5: d=2, 3, 4, 5, 6, 7, 8, 9
      k=6: d=5, 6
      k=7: d=4, 5, 6, 9
      k=8: d=5, 6
      k=9: d=2, 3, 4, 5, 6, 7, 8, 9
      k=10: d=5, 6

      We see that there is a repeating pattern, by count of the number of digits, of: (8, 2, 4, 2)…

      So for powers of: 1, 5, 9, 13, 17, … there is a choice of 8 possible digits (a 12.5% chance).

      For powers of: 2, 4, 6, 8, 10, 12, … there is a choice of 2 possible digits (a 50% chance).

      For powers of: 3, 7, 11, 15, … there is a choice of 4 possible digits (a 25% chance).

      The five girls have chosen 5 consecutive powers with two 50% chances (2), two 25% chances (4) and one 12.5% chance (8), so the part of the sequence they have chosen is … (4, 2, 8, 2, 4).

      We know the 8’s occur when k = 4n + 1.

      So the powers the girls have chosen are:

      (4n − 1, 4n, 4n + 1, 4n + 2, 4n + 3)

      These are 2-digit numbers, which limits n to the range [3, 24].

      The sum of the powers is:

      20n + 5

      and this needs to be a square number.

      >>> list(n for n in irange(3, 24) if is_square(20 * n + 5))
      [11]
      

      So, n = 11, and the girls numbers (and digits counts) are:

      43 (4), 44 (2), 45 (8), 46 (2), 47 (4)

      A and B both have counts of 2, C and D both have counts of 4, E has a count of 8.

      Like

  • Unknown's avatar

    Jim Randell 8:57 am on 16 April 2019 Permalink | Reply
    Tags:   

    Teaser 2952: Silly slip 

    From The Sunday Times, 21st April 2019 [link] [link]

    Please help me find my silly slip. I correctly added a five-figure number to a four-figure number to give a six-figure total. Then I tried to substitute letters for digits systematically and I ended up with:

    SILLY + SLIP = PLEASE

    However, in these letters I have made one silly slip, so please find it and then work out what the correct sum was.

    What was the correct six-figure numerical answer?

    This puzzle appears in the books The Sunday Times Brain Teasers 1 (2019) and The Sunday Times Teasers Book 1 (2021).

    [teaser2952]

     
    • Jim Randell's avatar

      Jim Randell 8:58 am on 16 April 2019 Permalink | Reply

      We can use the [[ bungled_sum() ]] solver (originally written for Puzzle 56).

      Run: [ @replit ]

      >>> bungled_sum(['SILLY', 'SLIP', 'PLEASE'])
                      L
      SILLY + SLIP = P?EASE / @[2,1] L -> ?
      97225 + 9271 = 106496 / ?=0 A=4 E=6 I=7 L=2 P=1 S=9 Y=5
      

      Solution: The numerical result of the sum is 106496.

      The mistake is in the L of PLEASE (the result of the sum), it should be a letter that is different from all the other letters, although that does make it hard to make an acceptable word, but we can check this makes a viable alphametic sum using the [[ SubstitutedSum() ]] solver from the enigma.py library.

      % python enigma.py SubstitutedSum "SILLY + SLIP = PXEASE"
      (SILLY + SLIP = PXEASE)
      (97225 + 9271 = 106496) / A=4 E=6 I=7 L=2 P=1 S=9 X=0 Y=5
      

      Like

      • Jim Randell's avatar

        Jim Randell 4:06 pm on 20 April 2019 Permalink | Reply

        I assumed this puzzle was in the same vein as other “bungled sum” problems.

        But the text says that letters are substituted for digits “systematically”, but it doesn’t say that each letter stands for a different digit (which is usual in alphametic puzzles).

        If we allow letters to stand for the same digit, then we can solve the alphametic sum:

        % python enigma.py SubstitutedExpression "SILLY + SLIP = PLEASE" --distinct=""
        (SILLY + SLIP = PLEASE)
        (99007 + 9091 = 108098) / A=0 E=8 I=9 L=0 P=1 S=9 Y=7
        [1 solution]
        

        The duplicated digits are: A and L are both 0, I and S are both 9.

        Like

      • Jim Randell's avatar

        Jim Randell 11:01 pm on 21 April 2019 Permalink | Reply

        Here is a faster (but longer) solution, using the minizinc.py library.

        from minizinc import (MiniZinc, var, alphametic, substitute)
        
        # the sum is a 5-digit number plus a 4-digit number and a 6-digit result
        #
        #    a b c d e      S I L L Y
        #      f g h i        S L I P
        #  -----------    -----------
        #  j k m n p q    P L E A S E
        
        fmt = "{abcde} + {fghi} = {jkmnpq}"
        
        # create the model
        p = MiniZinc(f"""
        
        include "globals.mzn";
        
        % the symbols in the incorrect sum
        {var("0..9", "AEILPSY")};
        
        constraint all_different([A, E, I, L, P, S, Y]);
        
        % symbols for the correct sum
        {var("0..9", "abcdefghijkmnpq")};
        
        % the correct sum
        constraint {alphametic(fmt)};
        
        % no leading zeros
        constraint a != 0 /\ f != 0 /\ j != 0;
        
        % the incorrect sum differs in only one place
        constraint sum([
          a != S, b != I, c != L, d != L, e != Y,
          f != S, g != L, h != I, i != P,
          j != P, k != L, m != E, n != A, p != S, q != E,
        ]) = 1;
        
        solve satisfy;
        
        """)
        
        # solve it
        for s in p.solve():
          # output the sum
          print(substitute(fmt, s))
        

        Like

  • Unknown's avatar

    Jim Randell 8:02 am on 16 April 2019 Permalink | Reply
    Tags: ,   

    Brain-Teaser 473: Gouttes d’Or 

    From The Sunday Times, 21st June 1970 [link]

    The conical glasses at the Hôtel d’Or hold one eighth of a litre and are embellished from base to brim with a picture of Bacchus. In making the hotel’s famous Gouttes d’Or, sold at NF 5.20, it was customary to fill the glass up to Bacchus’ neck (4/5th of the way up the glass) and then add an olive; the profit on raw materials was a modest 100 per cent.

    Gaston, the barman, has decided that he must make the more realistic profit of 400 per cent. So now the olive is put in first and then liquor is added up to the level of Bacchus’ chest (3/5ths of the way up the glass). The price has been reduced to NF 4.80.

    Gaston explained: “Ze olives are standard sized and cost me one centime a cc. Yes, I could put in ze olive after measuring out the liquid — but zen it would be necessary to charge …”

    How much?

    This is a corrected version of the originally published puzzle. In the original version the price of the first glass was incorrectly given as NF 5.30 (instead of NF 5.20). The puzzle can still be solved in the same way, but the numbers don’t work out as nicely.

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

    [teaser473]

     
    • Jim Randell's avatar

      Jim Randell 8:03 am on 16 April 2019 Permalink | Reply

      If the conical glass has a height of h and a radius (at the top) of r, then a completely full glass will have a volume of:

      𝛑 r² h / 3 = 125

      So, if it was filled to a height of (k/5) h (and hence a radius of (k/5) r, then the volume of liquid is:

      𝛑 (kr/5)² (kh/5) / 3 = (k/5)³ 125 = k³

      So a 4/5 full glass contains 64 cc, and a 3/5 full glass 27 cc.

      If olives have a volume of x cc (and cost 1 centime per cc) and the liquor has a cost of y centimes per cc, and the profit is 100% (i.e. the cost of the drink is twice the cost of the raw materials), then for the first glass we have:

      520 = 2(x + 64y)
      260 = x + 64y

      And for the second glass we have a 400% profit (i.e. the cost of the drink is 5 times the cost of the raw materials), on a drink with the olive added before the liquor we have:

      480 = 5(x + (27 − x)y)
      96 = x + 27y − xy

      (assuming the olive is submerged, and so displaces its own volume of liquid).

      These two equations have a reasonable solution at x = 4, y = 4. (And an unreasonable solution where x = 219, which is a very large olive, and wouldn’t fit in the glass).

      So the cost of a 3/5 glass, if the olive was added last, and the profit multiple is 5, would be:

      5(x + 27y) = 560

      Solution: The drink would cost NF 5.60.

      Here is a Python program that solves the puzzle numerically. It runs in 81ms.

      from enigma import (Polynomial, fdiv, find_zero, printf)
      
      # for a 4/5 full glass, with olive added last, the cost is k1, profit multiple is m1
      # for a 3/5 full glass, with olive added first, the cost is k2, profile multiple is m2
      # return (<olive volume>, <liquor cost>, <answer>)
      def solve(k1, m1, k2, m2):
      
        # volumes for a 4/5 and 3/5 glass
        (v4, v3) = (4**3, 3**3)
      
        # create a polynomial that gives the cost of liquor in terms of the volume of an olive
        # using the first equation:
        # k1 = m1 * (x + v4 * y)
        q = Polynomial([fdiv(k1, m1 * v4), fdiv(-1, v4)])
      
        # create the polynomial whose roots are the volume of an olive
        # using the second equation:
        # k2 = m2 * (x + (v3 - x) * y)
        p = q * Polynomial([v3, -1]) - Polynomial([fdiv(k2, m2), -1])
      
        # find a solution with a reasonably sized olive
        r =  find_zero(p, 0, 10)
        x = r.v
        y = q(x)
        # cost of a 3/5 glass, with an olive last, profit multiple m2
        k = m2 * (x + v3 * y)
        return (k, x, y)
      
      # solve for the required amounts
      (k, x, y) = solve(520, 2, 480, 5)
      
      printf("cost = NF {f:.02f} [x = {x:.02f}, y = {y:.02f}]", f=0.01 * k)
      

      If we change the first argument to [[ solve() ]] on line 30 to 530 we get the solution to the puzzle as originally set: approximately NF 5.72.

      Like

  • Unknown's avatar

    Jim Randell 8:05 am on 15 April 2019 Permalink | Reply
    Tags:   

    Teaser 2924: Snaking up 

    From The Sunday Times, 7th October 2018 [link] [link]

    A “Snakes and Ladders” board consists of a 10-by-10 grid of squares. In the first row (at the bottom) the squares are numbered from 1 to 10 from left to right, in the second row the squares are numbered 11 to 20 from right to left, in the third they are 21 to 30 from left to right again, and so on.

    An ant started on square 1, moved to square 2 and then, always moving to an adjacent square to the right or up, it finished in the top-right corner of the board. I have added up the total of the numbers on the squares it used and, appropriately, the total is a perfect square. In fact it is the square of one of the numbers the ant visited — the ant passed straight through it without turning.

    What was that total of the numbers used?

    [teaser2924]

     
    • Jim Randell's avatar

      Jim Randell 8:05 am on 15 April 2019 Permalink | Reply

      The ant makes 18 moves (9 across and 9 up). So we can make a path by choosing which of the 18 moves is an “up”, and the rest are all “across”.

      This Python program runs in 260ms.

      Run: [ @repl.it ]

      from enigma import (irange, subsets, is_square, find, printf)
      
      # construct the board
      b = list(irange(1, 100))
      for i in irange(10, 90, step=20):
        b[i: i + 10] = b[i + 9: i - 1: -1]
      
      # the ant makes 18 moves, 9 across (+1) and 9 up (+10)
      # so choose the up moves (move 0 is always across)
      for s in subsets(irange(1, 17), size=9):
        # construct the path
        p = 0
        path = [b[p]]
        for i in irange(0, 17):
          p += (10 if i in s else 1)
          path.append(b[p])
      
        # sum of the squares on the path is a perfect square...
        t = sum(path)
        r = is_square(t)
        if r is None: continue
        # ... of a number that is on the path
        i = find(path, r)
        if not (0 < i < 17): continue
        
        # the ant passes through the square without changing direction
        if (i - 1 in s) != (i in s): continue
      
        # output solution
        printf("sum = {t} (= {r}^2) {path}")
      

      Solution: The total of the numbers on the squares that the ant travelled through is 676.

      And: 676 = 26^2.

      There are three possible paths:

      (1, 2, 3, 18, 17, 16, 25, 26, 27, 28, 29, 30, 31, 50, 51, 70, 71, 90, 91)
      (1, 2, 3, 4, 17, 24, 25, 26, 27, 28, 33, 32, 31, 50, 51, 70, 71, 90, 91)
      (1, 2, 3, 4, 5, 16, 25, 26, 27, 28, 33, 32, 49, 52, 51, 70, 71, 90, 91)

      Like

  • Unknown's avatar

    Jim Randell 11:46 am on 14 April 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 472: [Marital law] 

    From The Sunday Times, 14th June 1970 [link]

    The monogamous and aptly named state of Swindlonabad has a number of inflexible marital laws, these being that:

    (a) Each male citizen must marry on his 21st birthday.

    (b) Each married man must contribute on his wedding day and each subsequent birthday to an Inheritance Trust which must be maintained at exactly the number of shekels equal to the square of the number of years he has lived.

    (c) When an individual’s trust fund can be precisely divided among all his legitimate unmarried sons, each son receiving a number of shekels equal to the square of that son’s age, the father retires and he and his family are maintained by the state.

    Now Abdul the Prolific fathered a child during each year of his married life, and all of these children survived to attend his retirement revels. Although only two of his many children were girls, he complained bitterly that such a misfortune should overtake him twice in a decade. At the time of his retirement only one of his daughters was under the age of ten.

    How old were the two daughters at that time?

    This puzzle was originally published with no title.

    [teaser472]

     
    • Jim Randell's avatar

      Jim Randell 11:46 am on 14 April 2019 Permalink | Reply

      Let’s consider the situation where Abdul is married for 21 years or more (i.e. his age is at least 42).

      Children over 20 have no claim on the trust fund, so he will have children with ages, 0, 1, 2, 3, …, 20. But two of them are girls, one of which is under 10, and the other is up to 10 years older than that, and they will have no claim.

      This Python program runs in 80ms.

      Run: [ @repl.it ]

      from enigma import irange, is_square, printf
      
      # total amount for children from 0 to 20 if they each have a claim
      T = sum(i * i for i in irange(0, 20))
      
      # consider the age of one of the daughters (less than 10)
      for a in irange(0, 9):
        # and the age of the older dauger (10 or more, and within 10 years)
        for b in irange(10, a + 10):
          # does this give a viable amount in the fund?
          A = is_square(T - a * a - b * b)
          if A is None or A < 42: continue
          # output solution
          printf("a={a} b={b} A={A}")
      

      Solution: The daughters were 9 and 17.

      Abdul retired on his 50th birthday, so his trust fund was 2500 shekels.

      He also had 29 children, one born every year from his 21st year to his 49th year.

      So the children’s ages range from 0 to 28. The daughters are aged 9 and 17, and only those sons aged less than 21 have a claim on the fund.

      And we can verify that the total claim is the same as the amount in the trust fund:

      >>> sum(i * i for i in diff(irange(0, 20), [9, 17]))
      2500
      

      The following code shows the total amount in the trust fund, the ages of the claimants and the total claim on the fund on each of Abdul’s birthdays from 21 to 50:

      from itertools import count
      from enigma import printf
      
      # record the ages of the sons
      sons = []
      
      # consider Abdul's age
      for A in count(21):
        # the total amount in the fund
        fund = A * A
      
        # count the total claim on the fund
        claim = sum(x * x for x in sons)
      
        printf("A={A}: fund={fund}, sons={sons}, claim={claim}")
        if claim == fund: break
      
        # increase the ages of the sons
        sons = list(x + 1 for x in sons if x < 20)
      
        # and each year a child is born
        # but at age 32 and 40 these are daughters
        if A not in (32, 40): sons.insert(0, 0)
      

      Which gives the following output:

      A=21: fund=441, sons=[], claim=0
      A=22: fund=484, sons=[0], claim=0
      A=23: fund=529, sons=[0, 1], claim=1
      A=24: fund=576, sons=[0, 1, 2], claim=5
      A=25: fund=625, sons=[0, 1, 2, 3], claim=14
      A=26: fund=676, sons=[0, 1, 2, 3, 4], claim=30
      A=27: fund=729, sons=[0, 1, 2, 3, 4, 5], claim=55
      A=28: fund=784, sons=[0, 1, 2, 3, 4, 5, 6], claim=91
      A=29: fund=841, sons=[0, 1, 2, 3, 4, 5, 6, 7], claim=140
      A=30: fund=900, sons=[0, 1, 2, 3, 4, 5, 6, 7, 8], claim=204
      A=31: fund=961, sons=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], claim=285
      A=32: fund=1024, sons=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], claim=385
      A=33: fund=1089, sons=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], claim=506
      A=34: fund=1156, sons=[0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], claim=649
      A=35: fund=1225, sons=[0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], claim=815
      A=36: fund=1296, sons=[0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], claim=1006
      A=37: fund=1369, sons=[0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], claim=1224
      A=38: fund=1444, sons=[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], claim=1471
      A=39: fund=1521, sons=[0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], claim=1749
      A=40: fund=1600, sons=[0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], claim=2060
      A=41: fund=1681, sons=[1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], claim=2406
      A=42: fund=1764, sons=[0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], claim=2788
      A=43: fund=1849, sons=[0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], claim=2766
      A=44: fund=1936, sons=[0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20], claim=2740
      A=45: fund=2025, sons=[0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20], claim=2710
      A=46: fund=2116, sons=[0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20], claim=2676
      A=47: fund=2209, sons=[0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20], claim=2638
      A=48: fund=2304, sons=[0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20], claim=2596
      A=49: fund=2401, sons=[0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20], claim=2550
      A=50: fund=2500, sons=[0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20], claim=2500
      

      and here it is as a graph:

      Like

  • Unknown's avatar

    Jim Randell 12:47 pm on 13 April 2019 Permalink | Reply
    Tags: by: D W Pye   

    Brain-Teaser 471: [Flower beds] 

    From The Sunday Times, 7th June 1970 [link]

    Plott was showing Green his garden. “A fine lawn”, commented Green. “Thank you. It’s remarkable, too. The sides run exactly north-south and east-west.”

    They strolled to a flower bed cut in the lawn. “When I came here”, said Plott, “there was just a triangle. One side, of 15 feet, was parallel to the north side of the lawn, and from its western end the second side rand due south for 22 feet. Rather a miserable affair. So I constructed these squares outwards from two sides; the north edge of the small square ran exactly along the north side of the lawn, while one corner of the large square just touched the east side of the lawn — where the flagpole now stands. But I want to enlarge it again”.

    “If I might make a suggestion”, replied Green, “you could join up the outside corners of the squares and give the bed a nice five-sided outline”. Plott thought this a good idea.

    Next day he ran a line from the flagpole to the north-east corner of the small square, and then worked on the triangle formed by this line, to east side of the small square and the side of the large square running from the small square to the flagpole.

    How many square feet were in this new piece?

    This puzzle was originally published with no title.

    [teaser471]

     
    • Jim Randell's avatar

      Jim Randell 12:48 pm on 13 April 2019 Permalink | Reply

      This is mostly an exercise in following the instructions to draw the following diagram:

      Red line segments are 15 ft, green line segments 22 ft, and blue line segments √(709) ft (but we don’t need to know that).

      We start with the right-angled triangle with red, green, blue sides on the left, and then add the red and blue squares. This lets us construct the desired (yellow shaded) triangle, which we see has a red N-S “base” of 15 ft, and by placing a second red, green, blue triangle within the blue square, we see the desired triangle has a green W-E “height” of 22ft. So it has the same area as the original triangle.

      Solution: The area of the triangle is 165 sq. ft.

      Like

  • Unknown's avatar

    Jim Randell 11:29 pm on 11 April 2019 Permalink | Reply
    Tags:   

    Teaser 2951: Imprismed 

    From The Sunday Times, 14th April 2019 [link] [link]

    A right regular prism has two ends with identical faces, joined by oblong rectangular faces. I have eight of them, with regular convex polygonal end-faces of 3, 4, 5, 6, 7, 8, 9 and 10 sides (triangle, square and so on). They sit on my flat desk (on oblong faces), and each prism has the same height.

    I chose three prisms at random, and was able to slide them into contact, broadside, in such a way that the middle one overhung both others (and could be lifted without disturbing them). Also, I was able to slide one outer prism to the other side, and the new “middle” prism was overhung by both others (and so vertically “imprisoned” by them).

    I was able to do all this again with three randomly chosen remaining prisms.

    Give the prior chance of this double selection (as a fraction in lowest terms).

    This puzzle appears in the books The Sunday Times Brain Teasers 1 (2019) and The Sunday Times Teasers Book 1 (2021).

    [teaser2951]

     
    • Jim Randell's avatar

      Jim Randell 11:30 pm on 11 April 2019 Permalink | Reply

      I’m not a great fan of this kind of puzzle. Partly because I don’t like probability much, but also because it is not easy to check that the answer you get works.

      I also think the wording for this particular puzzle could have been clearer. I started out with an incorrect interpretation, and got a different answer. If we consider the selection of an appropriate “special” set of three prisms (that can be arranged in the manner described in the puzzle text), then I think the puzzle is asking for the probability of selecting two consecutive “special” sets from the 8 prisms.

      Here is a Python program which works out the solution in 75ms.

      Run: [ @replit ]

      from enigma import (subsets, diff, ordered, fraction, printf)
      
      # prisms that project over another prism when placed side by side
      overhangs = {
        3: [],
        4: [],
        5: [3, 6, 7, 9, 10],
        6: [3, 7],
        7: [3],
        8: [3],
        9: [3, 6, 7, 10],
        10: [3, 7],
      }
      
      # over(x, y) = "x goes over y"
      over = lambda x, y: y in overhangs[x]
      
      # possible prisms
      prisms = sorted(overhangs.keys())
      
      # record special choices
      special = set()
      
      # choose the central prism
      for x in prisms:
        # and choose a left and right prism that are overhung by x
        for (l, r) in subsets(overhangs[x], size=2):
          # check there is a rearrangement that traps the new centre prism
          if over(l, r) or over(r, l):
            special.add(ordered(x, l, r))
      
      printf("{n} special sets", n=len(special))
      
      
      # record the total number of choices, and the number of that give two special sets
      t = n = 0
      
      # choose the first set of 3 prisms
      for s1 in subsets(prisms, size=3):
        # is it a special set?
        p1 = (ordered(*s1) in special)
      
        # choose the second set of 3 prisms
        for s2 in subsets(diff(prisms, s1), size=3):
          # is it a special set?
          p2 = (ordered(*s2) in special)
          if p1 and p2: n += 1
          t += 1
      
      # output the solution
      (a, b) = fraction(n, t)
      printf("chance = {n} / {t} = {a} / {b}")
      

      Solution: The probability of choosing two “special” sets is 3 / 140.


      Here is my analytical solution:

      There are 12 “special” arrangements (centre; outside) that allow a further “special” arrangement to be made from the remaining prisms. They group into 6 sets of mutually distinct pairs:

      (5; 3, 6) ↔ (9; 7, 10)
      (5; 3, 10) ↔ (9; 6, 7)
      (5; 6, 7) ↔ (9; 3, 10)
      (5; 6, 9) ↔ (10; 3, 7)
      (5; 7, 10) ↔ (9; 3, 6)
      (5; 9, 10) ↔ (6; 3, 7)

      There are also 4 “special” arrangements that do not allow a further “special” arrangement to be made:

      (5; 3, 7)
      (5; 3, 9)
      (5; 7, 9)
      (9; 3, 7)

      For the first choice of prisms there are C(8, 3) = 56 possible arrangements, and we must choose one of the arrangements that is part of a “special” pair.

      So, there is a probability of 12 / 56 = 3 / 14 of choosing a suitable first set of prisms.

      For the second choice there are C(8 − 3, 3) = 10 possible arrangements, but only one of these arrangements will be “special” – the arrangement that goes with the first choice to make one of the six “special” pairs given above.

      So overall probability of choosing two suitable sets is (3 / 14) × (1 / 10) = 3 / 140.

      Like

    • Robert Brown's avatar

      Robert Brown 7:44 am on 20 April 2019 Permalink | Reply

      Have you seen John Crabtree’s simple method? I’m also unhappy with probabilities, but wrote a simple program to count how many ways you can select 6 prisms from 8, and how many of these meet his algorithm. The ratio of these 2 numbers confirms the probability.

      Like

      • Jim Randell's avatar

        Jim Randell 2:39 pm on 20 April 2019 Permalink | Reply

        @Robert: Thanks for your comment.

        I try to provide a constructive solution where possible, so constructing the “special” sets, and then counting the number of desired outcomes from all possible outcomes seemed like the best way to understand the solution (and would be the approach least likely to contain a mistake). But it is good that other approaches are able to confirm the answer.

        For me the more difficult part was firstly interpreting what the puzzle was actually asking, and then constructing the “over” relation (to determine when one prism goes over another). Once that was done, counting the possibilities to come up with an answer was the easier part.

        I have got a manual approach to calculating the answer using probabilities, which I intend to post tomorrow along with the answer.

        I did also write code to run a million random trials in selecting six of the prisms to confirm the number I found (see the [[ teaser2951t.py ]] file on @replit).

        Like

    • Robert Brown's avatar

      Robert Brown 11:42 am on 22 April 2019 Permalink | Reply

      Jim
      I wasn’t being critical of your method, which corresponds to that used by the various people who solved it manually. Just drawing your attention to John’s clever method, which doesn’t use any lists – just a couple of rules. Rule one – 6 random selections don’t include 4 or 8 (probability 1/28) Rule 2 – dividing the 6 into 1st 3, then 2nd 3, prisms 6 & 10 must not be in the same group (probability 3/5).

      Like

      • Jim Randell's avatar

        Jim Randell 2:00 pm on 22 April 2019 Permalink | Reply

        It’s certainly neat. I suppose the issue I have is the need to demonstrate that the two rules generate exactly all possible pairs of “special” sets.

        Like

    • Robert Brown's avatar

      Robert Brown 7:42 am on 23 April 2019 Permalink | Reply

      After Rule 1, abc & def must use all of the other 6. Then after Rule 2 every pair within abc or def has one member overhanging the other.

      Like

  • Unknown's avatar

    Jim Randell 8:01 am on 11 April 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 470: Jacob’s ladder 

    From The Sunday Times, 31st May 1970 [link]

    Joseph’s garage, built at ground level on to the side wall of his house, had uniform external dimensions of (exactly) 10 ft. high by 10 ft. wide.

    Wishing to paint from the outside a top-floor window-frame over the garage, he positioned his longest ladder (whose length was over 30 ft.) with its foot on the ground at such a distance from the garage that its top rested against the house wall at the maximum height possible.

    Discovering, however, that despite this he could not reach up to the window, he borrowed his neighbour Jacob’s ladder and, positioning it similarly, found that he could now reach comfortably.

    With either ladder the length, distance and height referred to were all integral numbers of inches.

    How much longer was Jacob’s ladder than Joseph’s, and how much higher on the wall did it reach?

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

    [teaser470]

     
    • Jim Randell's avatar

      Jim Randell 8:02 am on 11 April 2019 Permalink | Reply

      For a ladder of length k, the maximum height we could achieve would be k, if we laid it flat against the wall, but we can’t do that because there is a garage in the way. If we position it at some distance away from the garage, so that it reaches over the garage we find that as we move the foot of the ladder towards the garage the other end will reach higher up the wall, until the garage gets in our way.

      If the foot of the ladder is at a distance d from the wall, and a height h up the wall, and touches the garage at a point 120 inches from the wall and 120 inches above the ground, then:

      h = 120d / (d − 120)

      and the length of the ladder k is given by:

      k = √(d² + h²)

      This program increases d (in inches from 120) looking for integer heights with integer length ladders.

      Run: [ @repl.it ]

      from enigma import (irange, is_square, printf)
      
      # consider increasing values for d > 120
      for d in irange(121, 240):
      
        # calculate the corresponding height h
        (h, r) = divmod(120 * d, d - 120)
        if r != 0: continue
      
        # calculate the length of the ladder
        k = is_square(d * d + h * h)
        if k is None: continue
        # ladder must be longer than 30 ft
        if not (k > 360): continue
      
        printf("ladder length = {k}, distance = {d}, height = {h}")
      

      Solution: Jacob’s ladder was 4 ft. 3 in. longer than Joseph’s, and reached 5 ft. 3 in. higher.

      In the diagram:

      Jacob’s ladder (blue) is 442 inches long (= 36 ft. 10 in.), and reaches a height of 408 inches (= 34 ft.) on the wall.

      Joseph’s ladder (red) is 391 inches long (= 32 ft. 7 in.) and reaches a height of 345 inches (= 28 ft. 9 in.) on the wall.

      There is a further possible ladder (green) which is 350 inches (= 29 ft. 2 in.) and would reach a height of 280 inches (= 23 ft. 4 in.) on the wall, but this ladder is not longer than 30 ft.

      We can also swap the distance and height to position the ladders, but this results in a maximum distance rather than a maximum height achieved.

      Like

  • Unknown's avatar

    Jim Randell 8:02 am on 10 April 2019 Permalink | Reply
    Tags:   

    Teaser 2925: The eternal triangle – Go figure! 

    From The Sunday Times, 14th October 2018 [link] [link]

    From my desk I saw the above when Leigh and Bob put 8392546137 and 4613725808 into two of the identical calculators used by my class. Everyone was told to press “clear”, then enter their unique three-figure pupil number (between 100 and 999) and divide this by the total number of display segments seen in it. If the result was a whole number they were to repeat the process with that result and its segment count (and so on until a decimal fraction part arose). Leigh, Bob and Geb each made four “divisions” this way. Using their three initial values as the sides of a triangle (Bob’s shortest, Geb’s longest), I told them to find its area.

    What was Leigh’s number?

    [teaser2925]

     
    • Jim Randell's avatar

      Jim Randell 8:03 am on 10 April 2019 Permalink | Reply

      This Python program runs in 87ms.

      Run: [ @replit ]

      from enigma import (irange, nsplit, sqrt, subsets, printf)
      
      # segment count per digit
      #            0  1  2  3  4  5  6  7  8  9
      segments = [ 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]
      
      # apply the process to n
      # return the number of applications
      def process(n):
        r = 0
        while n > 0:
          r += 1
          # count the segments
          s = sum(segments[d] for d in nsplit(n))
          (n, z) = divmod(n, s)
          if z != 0: return r
      
      # area of a triangle (using Heron's Formula)
      def heron(a, b, c):
        assert not (a < 0 or b < 0 or c < 0)
        r = (a + b - c) * (a + c - b) * (b + c - a)
        return (None if r < 0 else 0.25 * sqrt(r * (a + b + c)))
      
      # consider 3 digit numbers
      # and record those with a value of 4
      ns = list()
      for n in irange(100, 999):
        k = process(n)
        if k == 4:
          printf("[n={n}]")
          ns.append(n)
      
      # choose three of the numbers
      for (B, L, G) in subsets(ns, size=3):
        # check it forms a triangle
        A = heron(B, L, G)
        if not A: continue
        # output solution
        printf("B={B} L={L} G={G} [area={A:.3f}]")
      

      Solution: Leigh’s number was 756.

      There are only three 3-digit numbers that can be processed four times:

      640 → 40 → 4 → 1 → ½
      756 → 54 → 6 → 1 → ½
      810 → 54 → 6 → 1 → ½

      So the first number is Bob’s, the middle number is Leigh’s, and the last number is Geb’s.

      Used as sides of a triangle they enclose an area of √(51922261319), approximately 227864.568.

      Like

  • Unknown's avatar

    Jim Randell 8:22 am on 9 April 2019 Permalink | Reply
    Tags:   

    Brain-Teaser 469: [Safe combination] 

    From The Sunday Times, 24th May 1970 [link]

    Before his retirement, the Master Spy, enigmatic to the last, left instructions for opening his safe and recovering the Top Secret plans for Winning World Domination:

    “The combination is a 7-figure number, the sum of whose digits is 55. The first 4 figures make up a number divisible by 17, the sum of whose digits is also divisible by 17. The last 3 figures make up a number divisible by 7, the sum of whose digits is also divisible by 7.

    By now you should realise that there are 4 possible combinations. Since 3 of these all detonate a booby-trap, I’d better warn you that the correct number has no figure appearing more than 3 times”

    What is the combination of the safe?

    This puzzle was originally published with no title.

    [teaser469]

     
    • Jim Randell's avatar

      Jim Randell 8:23 am on 9 April 2019 Permalink | Reply

      We can treat this puzzle as a collection of alphametic expressions that can be handled by the [[ SubstitutedExpression() ]] solver from the enigma.py library.

      The following run file executes in 324ms.

      Run: [ @repl.it ]

      #! python3 -m enigma -rr
      
      # suppose the combination number is: ABCDEFG
      
      SubstitutedExpression
      
      --distinct=""
      --answer="ABCDEFG"
      
      # the digits sum to 55
      "A + B + C + D + E + F + G = 55"
      
      # the first four digits (and their sum) are divisible by 17
      "ABCD % 17 = 0"
      "(A + B + C + D) % 17 = 0"
      
      # the last three digits (and their sum) are divisible by 7
      "EFG % 7 = 0"
      "(E + F + G) % 7 = 0"
      
      # check no digit appears more than 3 times
      --code="check = lambda *s: all(s.count(d) < 4 for d in set(s))"
      "check(A, B, C, D, E, F, G)"
      

      Solution: The combination is 9979588.

      The four candidate numbers are: 9979777, 9979588, 9979966, 9979399.

      Like

    • GeoffR's avatar

      GeoffR 3:07 pm on 9 April 2019 Permalink | Reply

      
      % A Solution in MiniZinc
      include "globals.mzn";
      
      var 0..9:A; var 0..9:B; var 0..9:C; var 0..9:D; 
      var 0..9:E; var 0..9:F; var 0..9:G;
      
      constraint A >  0 /\ E > 0;
      
      var 1000000..9999999: ABCDEFG = 1000000*A + 100000*B + 10000*C + 1000*D + 100*E + 10*F + G;
      var 1000..9999: ABCD = 1000*A + 100*B + 10*C + D; 
      var 100..999: EFG = 100*E + 10*F + G;
      
      constraint A + B + C + D + E +  F + G == 55;
      
      constraint ABCD mod 17 == 0 /\ (A + B + C + D) mod 17 == 0;
      
      constraint EFG mod 7 == 0 /\ (E + F + G) mod 7 == 0;
      
      solve satisfy;
      
      output [ "Safe combination = " ++ show(ABCDEFG) ];
      
      % Safe combination = 9979966  << has 4 nines
      % Safe combination = 9979777  << has 4 sevens
      % Safe combination = 9979588  << has 3 nines  << the answer 
      % Safe combination = 9979399  << has 4 nines
      % ----------
      % ==========
      % Finished in 240msec
      

      Like

      • Jim Randell's avatar

        Jim Randell 5:18 pm on 9 April 2019 Permalink | Reply

        And we could add the following constraint to narrow the possibilities down to the single answer:

        constraint forall (d in 0..9) (at_most(3, [A, B, C, D, E, F, G], d));
        

        Like

  • Unknown's avatar

    Jim Randell 8:18 am on 8 April 2019 Permalink | Reply
    Tags: by: Brian Gladman   

    Teaser 2549: A round trip 

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

    I own a circular field with six trees on its perimeter. One day I started at one tree and walked straight to the next, continuing in this way around the perimeter from tree to tree until I returned to my starting point. In this way I found that the distances between consecutive trees were 12, 12, 19, 19, 33 and 33 metres.

    What is the diameter of the field?

    [teaser2549]

     
    • Jim Randell's avatar

      Jim Randell 8:19 am on 8 April 2019 Permalink | Reply

      I assumed the trees were visited by taking a direct straight line between them, rather than walking along an arc of the field boundary.

      We can cut the field (like a pizza) into sectors from the trees to the centre point. The field can then be rearranged (like a pizza) with the sectors in any order we like, and retain its circular shape.

      In particular we can rearrange the circle into two semi-circles each involving a 12, 19, and 33 sector.

      If we draw the quadrilateral formed from the trees in one of these semi-circles we get:

      The length of the lines are: AB = a, BC = b, CD = c, AD = x, AC = y, BD = z.

      As the triangles ABD and ACD are inscribed in a semi-circle they are right-angled:

      x² = a² + z²
      x² = c² + y²

      so:

      z² = x² − a²
      y² = x² − c²

      and multiplying these together:

      y²z² = x4 − (a² + c²)x² + a²c²

      Also, ABCD is a cyclic quadrilateral, so by Ptolomy’s Theorem [ link ]:

      yz = bx + ac

      squaring both sides:

      y²z² = b²x² + 2abcx + a²c²

      equating both expressions for y²z² we get:

      x4 − (a² + c²)x = b²x + 2abcx

      dividing by x, and simplifying:

      x³ − (a² + b² + c²)x − 2abc = 0

      We can look for a solution to this equation numerically:

      from enigma import (Polynomial, find_values, printf)
      
      # parameters
      (a, b, c) = (12, 19, 33)
      
      # form the polynomial
      p = Polynomial([-2 * a * b * c, -(a * a + b * b + c * c), 0, 1])
      
      # find a numerical solution in the required range
      (m, M) = (max(a, b, c), a + b + c)
      for r in find_values(p, 0, m, M):
        printf("diameter = {r.v:.3f} m")
      

      Solution: The diameter of the field is 44 metres.

      If there is an integer solution k, then the cubic polynomial is divisible by (x − k), so k will be a smallish divisor of the constant term in the polynomial, in this case 2abc.

      from enigma import (Polynomial, irange, printf)
      
      # parameters
      (a, b, c) = (12, 19, 33)
      
      # form the polynomial
      p = Polynomial([-2 * a * b * c, -(a * a + b * b + c * c), 0, 1])
      
      # possible range of solutions
      (m, M) = (max(a, b, c), a + b + c)
      
      # find integer roots in in the required range
      for x in p.roots(domain="Z", include="+"):
        if not (x < m or x > M):
          printf("diameter = {x} m")
      

      In fact using: a = 12, b = 19, c = 33 we get the following polynomial:

      x³ − 1594x − 15048 = 0

      which can be factorised as:

      (x − 44)(x² + 44x + 342) = 0

      Giving a positive root of 44, and negative roots of −22 ± √(142).

      There are only 5 divisors to be checked in the required range.

      Like

    • Jim Randell's avatar

      Jim Randell 11:28 pm on 8 April 2019 Permalink | Reply

      Here is an alternative approach that uses a bit less analysis, and works with any viable collection of distances.

      For a sector with a distance of d in a circle with radius r we can use the Cosine Rule [ link ] to calculate the angle at the centre of the circle:

      d² = 2r²(1 − cos(θ))
      cos(θ) = 1 − (d² / 2r²)

      We then just need to find a value for r, which makes the sum of the angles for all sectors achieve a value of 360°.

      Run: [ @replit ]

      from math import (acos, pi, fsum)
      from enigma import (fdiv, find_values, printf)
      
      # use the cosine rule to compute the angle at the centre of
      # the circle of radius r, for distance d
      angle = lambda r, d: acos(1.0 - 0.5 * fdiv(d, r)**2)
      
      # distances
      ds = (12, 12, 19, 19, 33, 33)
      
      # find a radius that makes the angles sum to 2pi
      f = lambda r: fsum(angle(r, d) for d in ds)
      for s in find_values(f, 2 * pi, 0.5 * max(ds), 0.5 * fsum(ds)):
        # output solution
        printf("diameter = {d:.3f} m", d=2.0 * s.v)
      

      Like

  • Unknown's avatar

    Jim Randell 11:01 am on 7 April 2019 Permalink | Reply
    Tags: ,   

    Brainteaser 1542: Precisely what do I mean? 

    From The Sunday Times, 29th March 1992 [link]

    There is a row of 10 boxes and each box contains one object, which is a knife, a fork or a spoon. Each of the three utensils is in at least one box. Here are five true statements to help you answer the questions below:

    1. A knife is in more boxes than a spoon is in;
    2. A spoon is in more boxes than a fork is in;
    3. A knife is not in precisely five boxes;
    4. A spoon is not in precisely three boxes;
    5. A fork is not in precisely half the number of boxes a spoon is in.

    How many boxes contain a knife?

    How many boxes contain a spoon?

    This puzzle is included in the book Brainteasers (2002), in which it appears in the following (slightly different) form:

    There is a row of ten boxes and each box contains one object, which is a knife, a fork or a spoon. There is at least one of each utensil. Here are five true statements to help you work out how many of each there are:

    • A knife is in more boxes than a spoon is in;
    • A spoon is in more boxes than a fork is in;
    • A knife is not in precisely five boxes;
    • A spoon is not in precisely three boxes;
    • A fork is not in precisely half the number of boxes a spoon is in.

    How many of each utensil are there?

    However I think both these formulations are flawed, in that under any reasonable interpretation there are no solutions. In the comments I present a variation that can be solved.

    [teaser1542]

     
    • Jim Randell's avatar

      Jim Randell 11:05 am on 7 April 2019 Permalink | Reply

      Having read the solution given in the book, I think the spirit of the puzzle can be maintained by phrasing it slightly differently:

      The National Museum of Cutlery in the small country of Ambiguity has an exhibit consisting of a row of ten boxes.

      Each box contains one object, which is either a knife, a fork or a spoon. There is at least one of each utensil.

      On a recent visit I heard five natives make the following true statements:

      1. A knife is in more boxes than a spoon is in.
      2. A spoon is in more boxes than a fork is in.
      3. A knife is not in precisely five boxes.
      4. A spoon is not in precisely three boxes.
      5. A fork is not in precisely half the number of boxes a spoon is in.

      How many of each utensil are there?

      And here is my solution:

      Suppose there are K knives, F forks and S spoons, each number has a value from 1 to 9.

      Looking at the statements:

      “A knife is in more boxes than a spoon is in”, seems to be an oddly worded way of saying: “there are more knives than spoons”:

      K > S

      Similarly: “A spoon is in more boxes than a fork is in”, seems to be saying:

      S > F

      We then have three statements of the form: “an X is not in precisely N boxes”

      I think there are two reasonable interpretations of this:

      (a) “The number of boxes containing an X, is not exactly N”

      i.e.:

      X ≠ N

      or:

      (b) “There are exactly N boxes, containing an object that is not an X”

      i.e.:

      10 − X = N

      The following Python 3 program considers these possible interpretations for the last three statements. It runs in 80ms.

      Run: [ @repl.it ]

      from enigma import (irange, join, printf)
      
      # decompose <t> into <k> increasing values
      def decompose(t, k, m=1, s=[]):
        if k == 1:
          if not (t < m):
            yield s + [t]
        else:
          for x in irange(m, t):
            yield from decompose(t - x, k - 1, x + 1, s + [x])
      
      # consider interpretations for:
      # "the number of boxes containing an <x> is <n>/<d>"
      def interpretations(x, n, d=1):
        # (a) "the number of boxes containing an <x> is exactly <n>/<d>"
        if d * x != n: yield 'a'
        # (b) "there are exactly <n>/<d> boxes containing an object that is not an <x>"
        if d * (10 - x) == n: yield 'b'
      
      # find possible values for F < S < K
      for (F, S, K) in decompose(10, 3):
        # consider possible interpretations for the last three statements
        ss = list(join(interpretations(*args)) for args in [(K, 5), (S, 3), (F, S, 2)])
        # each must have some interpretation
        if not all(ss): continue
        # output solution
        printf("F={F} S={S} K={K} {ss}")
      

      Solution: There is 1 fork, 4 spoons, 5 knives.

      The constraint (F < S < K) narrows the solution down to 4 possibilities:

      F=1, S=2, K=7
      F=1, S=3, K=6
      F=1, S=4, K=5
      F=2, S=3, K=5

      Only in the case (F=1, S=4, K=5) do the last three statements all have viable interpretations. These are:

      3. “A knife is not in precisely 5 boxes” = “There are exactly 5 boxes containing an object that is not a knife”
      4. “A spoon is not in precisely 3 boxes” = “The exact number of boxes containing a spoon is not 3”
      5. “A fork is not in precisely half the number of boxes a spoon is in” = “The exact number of boxes containing a fork is not half the exact number of boxes containing a spoon”

      or:

      3. “10 − K = 5”
      4. “S ≠ 3”
      5. “F ≠ S / 2”

      We can see each of these is a true statement, but they do not all use the same interpretation of the statement form. (Statement 3 uses the (b) interpretation. Statements 4, 5 use the (a) interpretation). This is why I changed the puzzle wording, so that the statements are made by different people. To have them made by the same person implies a consistent interpretation and gives no viable solutions.

      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