Recent Updates Toggle Comment Threads | Keyboard Shortcuts

  • Jim Randell 9:55 am on 12 July 2020 Permalink | Reply
    Tags:   

    Brainteaser 1835: Dominic’s dominoes 

    From The Sunday Times, 16th November 1997 [link]

    Dominic thought up a variation of the domino jigsaw game. He laid out a standard set of dominoes and produced the pattern below by copying the numbers of spots in each place. He put a 0 for all the blanks except for the one blank which stuck out of a side of the rectangle:

    Find the positions of all the dominoes.

    This puzzle was included in the book Brainteasers (2002, edited by Victor Bryant). The puzzle text above is taken from the book.

    [teaser1835]

     
    • Jim Randell 9:56 am on 12 July 2020 Permalink | Reply

      I used the [[ DominoGrid() ]] solver from the enigma.py library (see: Teaser 1590). We pair up one of the edge squares with a 0 to make a domino, then attempt to fit the rest into the remainder of the grid. The following program runs in 88ms.

      Run: [ @repl.it ]

      from enigma import DominoGrid, update, printf
      
      # the grid
      (X, Y, grid) = (5, 11, [
        6, 2, 6, 2, 0,
        6, 3, 1, 2, 0,
        3, 5, 1, 2, 0,
        3, 5, 3, 3, 1,
        6, 6, 5, 3, 0,
        4, 3, 0, 3, 2,
        2, 5, 4, 4, 4,
        4, 2, 4, 6, 6,
        5, 5, 4, 1, 1,
        2, 4, 1, 5, 0,
        1, 1, 0, 5, 6,
      ])
      
      # remove one of the border squares and solve for the rest
      for (i, b) in enumerate(grid):
        (y, x) = divmod(i, X)
        if x == 0 or x == X - 1 or y == 0 or y == Y - 1:
          # place the 0-b domino and solve for the remaining dominoes
          p = DominoGrid(X, Y, update(grid, [(i, None)]))
          for s in p.solve(used=[(0, b)]):
            printf("[0-{b} placed @ {x},{y}]\n")
            p.output_solution(s, prefix="  ")
      

      Solution: The layout of the dominoes is shown below:

      So the missing square is part of 0-2 domino.

      Like

  • Jim Randell 5:11 pm on 10 July 2020 Permalink | Reply
    Tags:   

    Teaser 3016: Eureka 

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

    Archimedes’ Principle states that the upward force on a floating body equals the weight of water displaced by the body. In testing this, Liam floated a toy boat in a cylindrical drum of water. The boat had vertical sides and took up one tenth of the surface area of the water. He also had some identical ball bearings (enough to fit snugly across the diameter of the drum), which were made of a metal whose density is a single-figure number times that of water.

    Liam loaded the boat with the ball bearings and noted the water level on the side of the drum. When he took the ball bearings out of the boat and dropped them in the water, the water level changed by an amount equal to the radius of a ball bearing.

    How many ball bearings did Liam have?

    [teaser3016]

     
    • Jim Randell 6:26 pm on 10 July 2020 Permalink | Reply

      Suppose there are n ball-bearings, each with a radius of r, then the radius of the cylindrical tank is nr.

      If we take the water level in the tank when the the unladen boat is floating in it to be “low water”, then when the balls are placed in the tank they displace an amount of water equal to their volume: n(4/3)πr³.

      The boat still has the same draught, so the water level in the tank increases by:

      (n(4/3)πr³) / (π(nr)²) = (4/3)(r/n)

      When the balls are instead placed in the boat, then the weight of the boat is increased by: kn(4/3)πr³ (where the metal of the balls is k times the density of water), and so this weight of water is displaced, so the level of water in the tank (above low water) is:

      kn(4/3)πr³ / ((9/10)π(nr)²) = (40/27)(kr/n)

      (the relative density of water is 1).

      The difference between these water levels is r:

      (40/27)(kr/n) – (4/3)(r/n) = r
      n = (4/27)(10k – 9)

      Only one value of k = 1..9 has (10k – 9) divisible by 27.

      This Python program looks for values of k that give an integer value for n:

      from enigma import irange, div, printf
      
      for k in irange(1, 9):
        n = div(40 * k - 36, 27)
        if n is None: continue
        printf("k={k} n={n}")
      

      Solution: [To Be Revealed]

      Like

  • Jim Randell 8:44 am on 9 July 2020 Permalink | Reply
    Tags: by: Ptolemaeus   

    Brain-Teaser 2: Stop watch 

    From The Sunday Times, 5th March 1961 [link]

    Setting one’s watch can be a tricky business, especially if it has a sweep second hand; for, unlike the hour and minute hands, the second hand is independent of the winder. The other day, when trying to set my watch by the midday time signal, I managed to get the hour hand and minute hand accurately aligned at 12 o’clock just as the pips signalled noon, but the second hand escaped me — in fact, on the pip of twelve it was just passing the 5-second mark. I can’t say that it was exactly on the 5-second mark, but it was within a second or two of it one way or the other. I didn’t bother to adjust it further in case I should finish up with the other hands wrong as well.

    That night I forgot to wind my watch and, the next morning, found that (not unnaturally) it had stopped. I noticed that the hour hand, the minute hand and the second hand were all exactly aligned one above another.

    (1) At exactly what time had my watch stopped?
    (2) Where exactly was the second hand pointing (to the very fraction of a second) on the pip of twelve noon the previous day?

    [teaser2]

     
    • Jim Randell 8:45 am on 9 July 2020 Permalink | Reply

      See also: Enigma 1761, Enigma 383, Enigma 404, Enigma 409.

      In each 12 hour period there are 11 times when the hour and minute hand coincide.

      This Python program looks at each of these eleven times, and works out far the second hand is ahead of its expected position if it is also coincident with the hour and minute hands. And if the second hand is between 3 and 7 seconds ahead of where it should be, then we have a solution to the puzzle.

      Run: [ @repl.it ]

      from fractions import Fraction as F
      from enigma import irange, sprintf as f, printf
      
      # format fractional seconds
      def fmt(s):
        (n, r) = divmod(s, 1)
        return f("{n:02d} + {r} s")
      
      # number of seconds in a period of the clock (12 hours)
      T = 12 * 60 * 60
      
      # find times at which the hour and minute hands coincide
      for i in irange(0, 10):
        t = F(T * i, 11)
        (h, ms) = divmod(t, 60 * 60)
        (m, s) = divmod(ms, 60)
        # the second hand should be at s, but is actually at ms/60
        # the difference should be between 3 and 7 seconds
        d = (F(ms, 60) - s) % 60
        if not(d < 3 or d > 7):
          printf("i={i} -> t={t} = {h:02d}:{m:02d}:{s}; diff = {d}", s=fmt(s), d=fmt(d))
      

      Solution: (1) The watch stopped at 8:43:38 + 2/11. (2) At exactly 12 noon the second hand was showing 5 + 5/11 seconds.

      Like

  • Jim Randell 9:36 am on 7 July 2020 Permalink | Reply
    Tags:   

    Teaser 2663: Missed the plot 

    From The Sunday Times, 6th October 2013 [link]

    My friend has a triangular vegetable plot, all sides being whole numbers of metres. Coincidentally, the dimensions of the plot are such that its perimeter (in metres) is the same as its area (in square metres). Also, the length of one of the sides is the average of the lengths of the other two sides.

    What are the lengths of the sides of the plot?

    [teaser2663]

     
    • Jim Randell 9:37 am on 7 July 2020 Permalink | Reply

      The triangle has sides of integer lengths (a, b, c) such that b = (a + c)/2.

      We can use Heron’s Formula [ @wikipedia ] to equate the area of the triangle with the perimeter, which gives us some restrictions on the sides of the triangle.

      However, we have encountered “equable” triangles before in Enigma 364, and generated a list of the 5 equable triangles, from which we can easily pick out the one that has one side that is an average of the other two.

      I also wrote code to generate k-equable triangles (integer sided triangles where the area is k times the perimeter), and that code can be reused here:

      Run: [ @repl.it ]

      from enigma import irange, isqrt, divc, divf, printf
      
      # find all triangles with integer sides where area = k . perimeter
      def triangles(k=1):
        K = 4 * k * k
        for p in irange(1, isqrt(3 * K)):
          for q in irange(max(p, divc(K + 1, p)), divf(3 * K, p)):
            (r, z) = divmod(K * (p + q), p * q - K)
            if r < q: break
            if z == 0: yield (p + q, p + r, q + r)
      
      # consider 1-equable triangles
      for (a, b, c) in triangles(1):
        if b - a == c - b:
          printf("a={a} b={b} c={c}")
      

      Solution: The lengths of the sides of the plot are: 6m, 8m, 10m.

      Like

    • GeoffR 10:54 am on 8 July 2020 Permalink | Reply

      
      for a in range (3, 25):
        for b in range (a+1, 25):
          for c in range(b+1, 25):
            # a < b < c and 2 * b = a + c
            if 2 * b != a + c: continue
            # Square of perimeter
            perim_sq = (a + b + c) ** 2
            # Area squared formula is based in Heron's formula
            area_sq = 1/16 *( 4*a*a*b*b - (a*a + b*b - c*c)**2)
            if perim_sq == area_sq:
              print(f"Length of sides are {a}, {b} and {c}m")
      
      # Length of sides are 6, 8 and 10m
      

      A (5,12,13) triangle has the area equal to the perimeter numerically, but does not have one side as the average of the other two sides.

      Like

  • Jim Randell 8:31 am on 5 July 2020 Permalink | Reply
    Tags:   

    Brainteaser 1823: The special seven 

    From The Sunday Times, 24th August 1997 [link]

    A “special seven” fraction is one whose decimal expansion uses only 7s and/or 0s. So examples of special sevens are:

    0.7707
    0.70707070…

    which are the decimal expansions of:

    7707/10000
    70/99

    respectively.

    You can set yourself all sorts of tasks with the special sevens. For example, is it possible to find some which add up to 1? In fact this is possible in many different ways, but…

    … what is the smallest number of special sevens adding to 1?

    This puzzle was included in the book Brainteasers (2002, edited by Victor Bryant). The puzzle text above is taken from the book.

    [teaser1823]

     
    • Jim Randell 8:32 am on 5 July 2020 Permalink | Reply

      Each “special seven” number corresponds to a “special one” number, which can be derived by dividing by 7.

      So if we find a collection of special sevens that sum to 1, there is a corresponding set of special ones that sum to 1/7.

      The decimal expansion of 1/7 = 0.(142857)…

      Which if we write it as a sum of special ones will require at least 8 of them to construct the 8 digit.

      Solution: The smallest number of special sevens that sum to 1 is 8.


      We can construct a collection of 8 special ones that sum to 1/7 as follows:

      0.(000100)...  [8]
      0.(000101)...  [7] = [6]
      0.(000101)...  [6]
      0.(000111)...  [5]
      0.(010111)...  [4] = [3]
      0.(010111)...  [3]
      0.(011111)...  [2]
      0.(111111)...  [1]
      -------------
      0.(142857)...
      

      (This is not the only set, the 0’s and 1’s in each column can be re-ordered to give other sets, and there is no reason why each recurring section should use the same arrangement of columns).

      Writing these as fractions (from [1] to [8]) we have:

      [1] = 0.(111111)... = 111111/999999 = 1/9
      [2] = 0.(011111)... = 11111/999999
      [3] = 0.(010111)... = 10111/999999
      [4] = 0.(010111)... = 10111/999999
      [5] = 0.(000111)... = 111/999999 = 1/9009
      [6] = 0.(000101)... = 101/999999
      [7] = 0.(000101)... = 101/999999
      [8] = 0.(000100)... = 100/999999
      

      Which sum to: 142857/999999 = 1/7 as required.

      Multiplying these values by 7 gives us a set of 8 special sevens that sum to 1:

      [1] = 0.(777777)... = 777777/999999 = 7/9
      [2] = 0.(077777)... = 77777/999999
      [3] = 0.(070777)... = 70777/999999
      [4] = 0.(070777)... = 70777/999999
      [5] = 0.(000777)... = 777/999999 = 7/9009
      [6] = 0.(000707)... = 707/999999
      [7] = 0.(000707)... = 707/999999
      [8] = 0.(000700)... = 700/999999
      

      Like

  • Jim Randell 5:14 pm on 3 July 2020 Permalink | Reply
    Tags:   

    Teaser 3015: Quid pro quo 

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

    In Readiland the unit of currency is the quid. Notes are available in two denominations and with these notes it is possible to make any three-figure number of quid. However, you need a mixture of the denominations to make exactly 100 quid. Furthermore, there is only one combination of denominations that will give a total of 230 quid.

    What are the two denominations?

    [teaser3015]

     
    • Jim Randell 5:32 pm on 3 July 2020 Permalink | Reply

      See also: Enigma 228, Enigma 1194, Enigma 1154.

      If we suppose the denominations are x and y (where gcd(x, y) = 1). Then the largest amount that cannot be made using the denominations is given by F(x, y) = xy – x – y.

      Both denominations are needed to make 100, so they must both be less than 100, and neither can be a divisor of 100.

      The following Python 3 program runs in 67ms.

      Run: [ @repl.it ]

      from enigma import coprime_pairs, express, printf
      
      # consider denominations x, y
      for (x, y) in coprime_pairs(97):
        if 100 % x == 0 or 100 % y == 0: continue
      
        # largest inexpressible amount is < 100
        if not(x * y - x - y < 100): continue
      
        # there is exactly 1 way to express 230
        e230s = list(express(230, (x, y)))
        if len(e230s) != 1: continue
      
        # output solution
        printf("x={x} y={y}; 100 -> {e100s}, 230 -> {e230s}", e100s=list(express(100, (x, y))))
      

      Solution: The two denominations are 3 quid and 49 quid.

      The largest amount that cannot be made using these denominations is 95 quid. All larger amounts are possible.

      The only way to make 100 quid is 17× 3 quid + 1× 49 quid.

      The only way to make 230 quid is 44× 3 quid + 2× 49 quid.


      Manually:

      The largest integer that is not expressible in k different ways using denominations x, y is given by:

      F[k](x, y) = kxy − x – y

      So we need to find co-prime values for x, y, less than 100 that are not divisors of 100, and the following hold:

      F[1](x, y) < 100
      F[2](x, y) ≥ 230

      This will ensure that all 3-digit amounts are expressible, and that to make 100 requires both denominations. All that remains for each pair of candidate denominations is to determine if there is a unique expression for 230.

      Given a value for x we can use the inequalities to find a range of viable values for y.

      Starting with x = 3, gives y = 47 .. 51 and only y = 47, 49 are co-prime with x.

      230 can be expressed in two ways using (3, 47): 230 = 14× 3 + 4× 47 = 61× 3 + 1× 47.

      230 can be expressed in only one way using (3, 49): 230 = 44× 3 + 2× 49.

      So (3, 49) is a viable solution.

      For x = 4, we get only y = 34, but x divides 100, so this is not a candidate solution.

      And for larger values of x there are no possibilities for y, so we are done.

      Like

  • Jim Randell 8:37 am on 2 July 2020 Permalink | Reply
    Tags:   

    Teaser 2748: I go up and up 

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

    I have in mind an arithmetic progression; ie, a sequence which goes up and up by a fixed amount (such as 1, 10, 19, 28, …) and — as in that example — one of the terms of my progression will eventually be 10000. But I have coded the numbers by consistently replacing digits by letters and in this way the arithmetic progression has become

    I, GO, UP, AND, …

    Find the value of POUND.

    [teaser2748]

     
    • Jim Randell 8:38 am on 2 July 2020 Permalink | Reply

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

      The following run file executes in 93ms.

      Run: [ @repl.it ]

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedExpression
      
      # the given terms must be evenly spaced
      "GO - I == UP - GO"
      "UP - GO == AND - UP"
      
      # and eventually we reach 10000
      "div(10000 - I, GO - I) > 0"
      
      --answer="POUND"
      

      Solution: POUND = 28706.

      The first 4 terms in the progression are:

      4, 38, 72, 106, …

      Each term being derived from the previous term by adding 34. So the sequence is:

      S(n) = 4 + 34n
      S(294) = 10000

      Like

  • Jim Randell 9:25 am on 30 June 2020 Permalink | Reply
    Tags:   

    Brain-Teaser 524 

    From The Sunday Times, 27th June 1971 [link]

    At a party at my friend Smith’s house recently, we were watching a rather attractive couple who were evidently enjoying each other’s company.

    “I don’t know those two”, I said, “but I should be interested to know the lady’s age”.

    “Well, I’m not the man to be explicit about that subject”, said Smith, “even though I know she’s rather proud of it. But her age is the sum of the digits in the sum of the digits in all the numbers from one to a hundred thousand inclusive”.

    “Certainly not very explicit”, I said, “but then, how old is her companion?”

    “Believe it or not”, said Smith, “but his age is the sum of the digits in the sum of the digits in all the numbers from one to a million inclusive”.

    What was the difference between their ages?

    [teaser524]

     
    • Jim Randell 9:26 am on 30 June 2020 Permalink | Reply

      It is not too onerous to tackle the problem directly using Python.

      This program counts the digits in each of the required sequences. It runs in 405ms.

      Run: [ @repl.it ]

      from enigma import fcompose, nsplit, irange, printf
      
      # sum the digits in a number
      dsum = fcompose(nsplit, sum)
      
      # sum the digits of the numbers in a sequence
      dsums = lambda s: sum(map(dsum, s))
      
      # age of the lady
      a1 = dsum(dsums(irange(1, 100_000)))
      
      # age of the gentleman
      a2 = dsum(dsums(irange(1, 1_000_000)))
      
      printf("a1={a1} a2={a2}, diff={d}", d=abs(a1 - a2))
      

      Solution: They are the same age, so the difference is 0.


      But it is also fairly straightforward so solve analytically:

      If we suppose DS(k) is the sum of the digits in the integers (represented in base 10), starting from 0, that are less than k, then:

      The sum of the digits in 0 .. 9 is 45.

      DS(10^1) = 45

      If we then consider numbers from 0 .. 99, the units digits comprise 10 lots of DS(10), and the tens digits comprise another 10 lots of DS(10):

      DS(10^2) = 20 DS(10^1) = 900

      For the digits from 0 .. 999, the tens and units digits together comprise 10 lots of DS(100), and the hundreds digits comprise 100 lots of DS(10).

      DS(10^3) = 10 DS(10^2) + 100 DS(10^1) = 13,500

      Carrying on this construction we find:

      DS(10^n) = 45n × 10^(n – 1)

      (See: OEIS A034967 [ @oeis ]).

      The sums we are interested in are therefore:

      DS(10^5) = 45×5×(10^4) = 2,250,000
      DS(10^6) = 45×6×(10^5) = 27,000,000

      The extra 0 at the beginning doesn’t make any difference, but we need to add in the digits for the end points, which are both powers of 10, so only contribute an extra 1.

      So we are interested in the digit sums of 2,250,001 and 27,000,001, both of which are 10.

      So both ages are 10, and their difference is 0.

      Like

  • Jim Randell 8:10 am on 28 June 2020 Permalink | Reply
    Tags: by: Colin   

    Brainteaser 1822: Teasing triangles 

    From The Sunday Times, 17th August 1997 [link]

    Each of the ten line segments in the picture have been given a different whole number value from 0 to 9. A figure shown in a triangle equals the sum of the three values assigned to the sides of the triangle. The figures which have not been given from the other two triangles are the same as each other and the two add together to give a perfect square.

    What are the numbers assigned to each side?

    This puzzle was included in the book Brainteasers (2002, edited by Victor Bryant). The puzzle text above is taken from the book.

    [teaser1822]

     
    • Jim Randell 8:11 am on 28 June 2020 Permalink | Reply

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

      The following run file executes in 96ms.

      Run: [ @repl.it ]

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedExpression
      
      # regions given
      "A + F + G = 9"
      "E + F + H = 7"
      "C + I + J = 23"
      
      # remaining regions have the same value...
      "B + G + J == D + H + I"
      # ... and sum to a square
      "is_square(B + D + G + H + I + J)"
      
      # suppress verbose output
      --template=""
      

      Solution: The numbers assigned to each line are shown below:

      Like

      • Jim Randell 12:38 pm on 30 June 2020 Permalink | Reply

        The puzzle as originally published in The Sunday Times was worded as follows:

        Each of the ten line segments in the picture have been given a different whole number value from 0 to 9. A figure shown in a triangle equals the sum of the three values assigned to the sides of the triangle. The figures which have not been given from the other two triangles when added together to give 30. What is the value assigned to CD?

        CD being the external edge of the 23 triangle (which is the value C in my solution).

        We can adjust the run-file accordingly:

        #!/usr/bin/env python -m enigma -r
        
        SubstitutedExpression
        
        # regions given
        "A + F + G = 9"
        "E + F + H = 7"
        "C + I + J = 23"
        
        # the other two triangles added together to give 30
        "B + D + G + H + I + J = 30"
        
        --answer="C"
        
        # suppress verbose output
        --template=""
        

        And we find that there are 24 ways to fill out the numbers, but the value on the required edge is always 9.

        Like

    • GeoffR 4:09 pm on 29 June 2020 Permalink | Reply

      
      % A Solution in MiniZinc
      include "globals.mzn";
      
      % using the vertex labels A,B,C,D and E (as original diagram in link)
      % plus F for the central point
      
      % outside edges of the pentagon
      var 0..9:AB; var 0..9:BC; var 0..9:CD; var 0..9:DE; var 0..9:EA;
      
      % internal lines to central point F
      var 0..9:AF; var 0..9:BF; var 0..9:CF; var 0..9:DF; var 0..9:EF;
      
      constraint all_different ([AB, BC, CD, DE, EA, AF, BF, CF, DF, EF]);
      
      % three given triangles are AEF, ABF and CDF
      constraint AF + EF + EA == 7;
      constraint AB + AF + BF == 9;
      constraint CF + DF + CD == 23;
      
      % the other two triangle sides (BCF and DEF) are the same total 
      % and the two add together to give a perfect square
      
      constraint DE + EF + DF == BF + CF + BC;
      
      set of int: sq = {16, 25, 36, 49, 64, 81};
      constraint (DE + EF + DF + BF + CF + BC) in sq;
      
      solve satisfy;
      
      % AB = 0; BC = 3; CD = 6; DE = 5; EA = 1;
      % AF = 2; BF = 7; CF = 8; DF = 9; EF = 4;
      % % time elapsed: 0.06 s
      % ----------
      % ==========
      
      

      Like

    • GeoffR 1:46 pm on 8 July 2020 Permalink | Reply

      My solution below is updated for the original Sunday Times description, the solution above being the solution being based on the teaser in the book Brainteasers (2002, edited by Victor Bryant).

      
      % A Solution in MiniZinc - original Sunday Times teaser
      include "globals.mzn";
       
      % using the vertex labels A,B,C,D and E (as original ST diagram in link)
      % plus F for the central point
       
      % outside edges of the pentagon
      var 0..9:AB; var 0..9:BC; var 0..9:CD; var 0..9:DE; var 0..9:EA;
       
      % internal lines to central point F
      var 0..9:AF; var 0..9:BF; var 0..9:CF; var 0..9:DF; var 0..9:EF;
       
      constraint all_different ([AB, BC, CD, DE, EA, AF, BF, CF, DF, EF]);
       
      % three given triangles are AEF, ABF and CDF
      constraint AF + EF + EA == 7;
      constraint AB + AF + BF == 9;
      constraint CF + DF + CD == 23;
      
      % for figures in triangles not given ie triangles DEF and BCF
      constraint DE + EF + DF + BF + CF + BC == 30; 
       
      solve satisfy;
      output ["CD = " ++ show(CD) ];
      
      % CD = 9
      % ----------
      % ==========
      
      

      Like

  • Jim Randell 5:08 pm on 26 June 2020 Permalink | Reply
    Tags:   

    Teaser 3014: Family business 

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

    George and Martha run a company with their five daughters. The telephone extensions all have four positive unequal digits and strangely only four digits appear in the seven extensions:

    Andrea: ABCD
    Bertha: ACDB
    Caroline: BACD
    Dorothy: DABC
    Elizabeth: DBCA
    George: CABD
    Martha: CDAB

    They noticed the following:

    Andrea’s and Bertha’s add up to Dorothy’s.
    Bertha’s and Elizabeth’s add up to George’s.
    Caroline’s and Dorothy’s add up to Martha’s.

    What is Andrea’s extension?

    [teaser3014]

     
    • Jim Randell 5:14 pm on 26 June 2020 Permalink | Reply

      Any one of the expressions is sufficient to determine the answer.

      I used the [[ SubstitutedExpression() ]] solver from the enigma.py library to evaluate the alphametic expressions.

      The following run file executes in 96ms.

      Run: [ @repl.it ]

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedExpression
      
      --digits="1-9"
      
      "ABCD + ACDB = DABC"
      "ACDB + DBCA = CABD"
      "BACD + DABC = CDAB"
      
      --answer="ABCD"
      

      Solution: Andrea’s extension is 2385.


      Here’s my manual solution:

      We can split each of the three sums into columns to give us partial equations, that may have a carry out or a carry in.

      B + D = C appears at both the left- and right-hand side of a sum, so can’t have a carry in or a carry out, so it is a complete equation.

      We then see that the partial sum BC + CD = AB cannot have a carry in, so the sum A + B = D is also a complete equation.

      The sum A + A = D cannot have a carry out, and if it does not have a carry in then we deduce that B = A, which is not possible. So it does have a carry in, and B = A + 1 is a complete equation.

      Using these three complete equations we derive:

      B = A + 1
      D = 2A + 1
      C = 3A + 2

      For digits in the range 1-9 the only viable values are:

      A = 1, B = 2, C = 5, D = 3
      A = 2, B = 3, C = 8, D = 5

      Only one of these assignment works in the original three sums, so we have the answer.

      Or, we can use the partial equation BC + CD = AB, which we now know must have a carry out, to give a fourth complete equation: 9B + 11C + D = 10A + 100. We can then substitute in the other equations to get the value of A, and from that the remaining values:

      9B + 11C + D = 10A + 100
      9(A + 1) + 11(3A + 2) + (2A + 1) = 10A + 100
      44A + 32 = 10A + 100
      34A = 68
      A = 2, B = 3, C = 8, D = 5

      Like

    • GeoffR 9:19 am on 27 June 2020 Permalink | Reply

      I simulated a normal addition sum in MiniZinc for the first equation to find an answer.

      The values obtained confirmed the other two equations.

      % A Solution in MiniZinc
      include "globals.mzn";
       
      % Using the first equation only ie Andrea + Bertha = Dorothy
      % 
      %  A B C D
      %  A C D B
      %  -------
      %  D A B C
      %  -------
      
      var 1..9:A; var 1..9:B; var 1..9:C; var 1..9:D;
      var 0..1:carry1; var 0..1:carry2; var 0..1:carry3; 
      
      constraint C == (B + D) mod 10 
      /\ carry1 = (B + D) div 10;
      
      constraint B = (carry1 + C + D) mod 10 /\ 
      carry2 = (carry1 + C + D) div 10;
      
      constraint A = (carry2 + B + C) mod 10
      /\ carry3 = (carry2 + B + C) div 10;
      
      constraint D = carry3 + 2*A;
      
      solve satisfy;
      
      output ["A,B,C,D = " ++ show([A,B,C,D]) ];
      
      
      

      Like

    • GeoffR 2:41 pm on 27 June 2020 Permalink | Reply

      A short Python programme confirms that the second and third equations give the same value for Andrea’s extension as my MiniZinc programme for the first equation:

      
      from itertools import permutations
      
      # Bertha’s and Elizabeth’s extensions add up to George’s extn.
      # 2nd Equation: ACDB + DBCA = CABD
      
      for p in permutations((1,2,3,4,5,6,7,8,9),4):
          a, b, c, d = p
          acdb = 1000*a + 100*c + 10*d + b
          dbca = 1000*d + 100*b + 10*c + a
          cabd = 1000*c + 100*a + 10*b + d
          if acdb + dbca == cabd:
              # Find Andrea's extension
              abcd = 1000*a + 100*b + 10*c + d
              print("2. Andrea's extension =", abcd)
      
      # Caroline’s and Dorothy’s extensions add up to Martha’s extn.
      # 3rd Equation : BACD + DABC = CDAB
      
      for p in permutations((1,2,3,4,5,6,7,8,9),4):
          a, b, c, d = p
          bacd = 1000*b + 100*a + 10*c + d
          dabc = 1000*d + 100*a + 10*b + c
          cdab = 1000*c + 100*d + 10*a + b
          if bacd + dabc == cdab:
              # Find Andrea's extension
              abcd = 1000*a + 100*b + 10*c + d
              print("3. Andrea's extension =", abcd)
      
      

      Like

  • Jim Randell 7:16 am on 25 June 2020 Permalink | Reply
    Tags: by: H. Wright   

    Brain-Teaser 1: Tall story 

    From The Sunday Times, 26th February 1961 [link]

    “We’re a biggish family in more ways than one”, said Jeremy. “Five, including triplets, and three of us the same height. I’m 6 ft. and aged 72; Jim is three inches taller than John and three years older; and John and Julian’s combined heights are 5 ft. 11 in. more than Joe’s and their combined ages 71 years more than his. Our aggregate height in inches equals our aggregate age in years, but no one’s age in years equals Joe’s height in inches”.

    What were the name, age and height of the tallest of the triplets?

    This was the first of the regular Teaser puzzles published in The Sunday Times. It was accompanied by the following introduction:

    Brain-Teasers: a Weekly Feature

    Great numbers of our readers have found entertainment and interest in the Brain-Teasers, or mathematical problems, which we have published from time to time, usually at holiday week-ends. Now we intend to make them a weekly feature of The Sunday Times.

    Readers themselves have supplied many of the best of the problems in the past, and we invite them to continue to do so. A fee of £10 will be paid for each problem accepted.

    Problems should fulfil the following conditions: Both the problem and the solution must be expressible in reasonably brief compass. No advanced or specialist mathematical techniques should be necessary. Solutions should be unique, or otherwise admit of no uncertainty in judging. Problems must be original. Diagrams are admissible if they are not too complicated.

    The problem below is the invention of a reader who observes: “Any who are stumped by it after the expiry of an hour should feel cause for concern”.

    A prize of £3 was offered.

    [teaser1]

     
    • Jim Randell 7:17 am on 25 June 2020 Permalink | Reply

      We can associate values (A, B, C, D, E) with (Jez, Jim, Jon, Jul, Joe), that correspond to either their heights in inches or their ages in years, both give rise to the same set of equations:

      A = 72
      B = C + 3
      C + D = E + 71
      x = y = z

      where (x, y, z) are some three of (A, B, C, D, E).

      This gives us a set of 5 simultaneous equations in 5 variables.

      This Python program finds solutions to these equations (using the [[ matrix.linear() ]] solver from the enigma.py library), groups the solutions by the sum of the set of values, and then looks for two sets with the same sum (one set for the ages, and another set for the height) that satisfy the condition that Joe’s height does not appear in the set of ages.

      It runs in 55ms.

      Run: [ @repl.it ]

      from enigma import subsets, matrix, multiset, group, printf
      
      # labels for the people involved
      # A = Jez, B = Jim, C = Jon, D = Jul, E = Joe
      labels = (A, B, C, D, E) = (0, 1, 2, 3, 4)
      
      # solve equations specified as: (ps, ms, k)
      # for integer solutions
      def solve(eqs):
        (A, B) = (list(), list())
        for (ps, ms, k) in eqs:
          eq = [0] * 5
          for (i, n) in multiset(ps).items(): eq[i] += n
          for (i, n) in multiset(ms).items(): eq[i] -= n
          A.append(eq)
          B.append(k)
        r = None
        try:
          r = matrix.linear(A, B)
        except ValueError as e:
          # skip "inconsistent" errors
          if e.args[0] == "inconsistent": return
          # but raise anything else
          raise
        # extract integer results
        (r, f) = zip(*(divmod(x, 1) for x in r))
        if not any(f): return r
      
      # find values that satisfy the equations
      def generate():
        # choose the three with the same value
        for (x, y, z) in subsets(labels, size=3):
          # solve the equations
          r = solve([
            ([A], [], 72), # A = 72
            ([B], [C], 3), # B = C + 3
            ([C, D], [E], 71), # C + D = E + 71
            ([x], [y], 0), # x = y
            ([y], [z], 0), # y = z
          ])
          if r is None: continue
          # check the composition is [1, 1, 3]
          if sorted(multiset.from_seq(r).values()) == [1, 1, 3]:
            yield r
      
      # group sets of solutions by the sum of the values
      d = group(generate(), by=sum)
      
      # consider values for the sum
      for (t, rs) in d.items():
        # choose two sets of values for the ages and heights
        for (age, height) in subsets(rs, size=2, select="M"):
          # no one's age is the same as Joe's height
          if height[E] in age: continue
          for (n, a, h) in zip("Jez Jim Jon Jul Joe".split(), age, height):
            printf("{n}: age {a} yr, height {h} in")
          printf()
      

      Solution: Jim is the tallest of the triplets. His age is 72, his height is 6ft 2in.

      The complete characteristics are:

      Jez: age 72 yr, height 72 in
      Jim: age 72 yr, height 74 in
      Jon: age 69 yr, height 71 in
      Jul: age 74 yr, height 71 in
      Joe: age 72 yr, height 71 in

      So: Jeremy, Jim, Joe are the triplets (same age), and: John, Julian, Joe are the same height.

      There are 7 ways to solve the equations, but there is only one pair that has the same sum, and this gives rise to the solution.

      Like

    • GeoffR 4:10 pm on 25 June 2020 Permalink | Reply

      I found three solutions in MinZinc.

      The first solution was invaiid as there was no single maximum height.

      The second solution was the same as Jim’s solution above.

      There appears to be another solution, which gives the maximum height of Jim as 6ft 3 in, with an age of 75 years. If the puzzle had stated that age and height could not be the same, then this last solution could be ruled out – it appears to conform to the stated conditions in the puzzle.

      
      % A Solution in MiniZinc
      include "globals.mzn";
       
      var 10..99: JezAge; var 10..99: JimAge; var 10..99: JonAge; 
      var 10..99: JulAge; var 10..99: JoeAge; 
      
      var 50..80: JezHt; var 50..80: JimHt; var 50..80: JonHt; 
      var 50..80: JulHt; var 50..80: JoeHt; 
      
      % Three of us the same height
      % (A,B,C,D,E) = (Jez, Jim, Jon, Jul, Joe)
      constraint (JezHt == JimHt /\ JimHt == JonHt)  % ABC
      \/ (JezHt == JimHt /\ JimHt == JulHt)   % ABD
      \/ (JezHt == JimHt /\ JimHt == JoeHt)   % ABE
      \/ (JezHt == JonHt /\ JonHt == JulHt)   % ACD
      \/ (JezHt == JonHt /\ JonHt == JoeHt)   % ACE
      \/ (JezHt == JulHt /\ JulHt == JoeHt)   % ADE
      \/ (JimHt == JonHt /\ JonHt == JulHt)   % BCD
      \/ (JimHt == JonHt /\ JonHt == JoeHt)   % BCE
      \/ (JimHt == JulHt /\ JulHt == JoeHt)   % BDE
      \/ (JonHt == JulHt /\ JulHt == JoeHt);  % CDE
      
      % Three of us the same age(triplets)
      constraint (JezAge == JimAge /\ JimAge == JonAge)  % ABC
      \/ (JezAge == JimAge /\ JimAge == JulAge)   % ABD
      \/ (JezAge == JimAge /\ JimAge == JoeAge)   % ABE
      \/ (JezAge == JonAge /\ JonAge == JulAge)   % ACD
      \/ (JezAge == JonAge /\ JonAge == JoeAge)   % ACE
      \/ (JezAge == JulAge /\ JulAge == JoeAge)   % ADE
      \/ (JimAge == JonAge /\ JonAge == JulAge)   % BCD
      \/ (JimAge == JonAge /\ JonAge == JoeAge)   % BCE
      \/ (JimAge == JulAge /\ JulAge == JoeAge)   % BDE
      \/ (JonAge == JulAge /\ JulAge == JoeAge);  % CDE
      
      % Jez is 6 ft. and aged 72
      constraint JezHt == 72 /\ JezAge == 72;
      
      % Jim is three inches taller than John and three years older
      constraint JimHt - 3 == JonHt /\ JimAge - 3 == JonAge;
      
      %  John and Julian’s combined heights are 5 ft. 11 in. more than Joe’s
      %  and their combined ages 71 years more than his
      constraint JonHt + JulHt - 71 == JoeHt;  
      constraint JonAge + JulAge - 71 == JoeAge;
      
      % Our aggregate height in inches equals our aggregate age in years
      constraint  JimHt + JezHt + JulHt + JonHt + JoeHt 
      == JimAge + JezAge + JulAge  + JonAge + JoeAge;
      
      % No one’s age in years equals Joe’s height in inches
      constraint JoeHt != JezAge /\ JoeHt != JimAge
      /\ JoeHt != JonAge /\ JoeHt != JulAge;
      
      solve satisfy;
      
      output ["Ages: " ++ show([JezAge, JimAge, JonAge, JulAge, JoeAge])]++
      ["\nHeights: " ++ show([JezHt, JimHt, JonHt, JulHt, JoeHt])];
      
      %           Jez Jim Jon Jul Joe
      % Ages:    [72, 72, 69, 72, 70]  << no single tallest member 
      % Heights: [72, 72, 69, 72, 70]  << Therefore, an invalid solution
      % ----------
      % Ages:    [72, 72, 69, 74, 72]  <<  Jim is tallest member at 6 ft. 2 in.
      % Heights: [72, 74, 71, 71, 71]  <<  with an age of 72 years
      % ----------
      % Ages:    [72, 75, 72, 72, 73]  << Jim is tallest member at 6 ft. 3 in.
      % Heights: [72, 75, 72, 72, 73]  <<  with an age of 75 years
      % ----------
      % ==========
      
      
      

      Like

      • Jim Randell 4:15 pm on 25 June 2020 Permalink | Reply

        @Geoff: The condition “no one’s age in years equals Joe’s height in inches”, means that Joe’s age is not equal to Joe’s height. So this disposes of two of your solutions. (And effectively means that the same set of solutions cannot be used for both ages and heights).

        Like

    • GeoffR 4:38 pm on 25 June 2020 Permalink | Reply

      @Jim: Fair point. I was interpreting only other people’s ages only could not be equal to Joe’s height. It could have been more clearly stated that this condition also applied to Joe himself!

      Like

  • Jim Randell 8:52 am on 23 June 2020 Permalink | Reply
    Tags: by: DJT Hogg   

    Teaser 2525: Sandwich filling 

    From The Sunday Times, 13th February 2011 [link]

    “Sandwich numbers” are those of the form BFB, where B is the bread and is a single digit, and F is the filling of any length: BFB has to be divisible by F. For example, 11371 is a sandwich with filling 137 since 11371 = 83 × 137. Incidentally, all of 21372, 31373, … , 91379 are also sandwich numbers, and these nine are said to make up a “sandwich box”.

    The filling in my sandwich box today is the smallest beginning with a 3.

    What is my filling?

    [teaser2525]

     
    • Jim Randell 8:58 am on 23 June 2020 Permalink | Reply

      My first thought was to generate integers that start with a 3, and then check to see if they make a “sandwich box”. But this was taking a long time, so here’s some analysis to produce a faster program:

      If f is an n digit “filling” number, then the corresponding sandwich numbers in a sandwich box are:

      b.10^(n + 1) + 10.f + b

      for b = 1 .. 9. And each of these must be divisible by f.

      Clearly f will divide the 10.f part, which leaves b(10^(n + 1) + 1), when b = 1, we must have f divides (10^(n + 1) + 1), and if this is the case f will divide the remaining sandwich numbers with b > 1.

      So, f must be a divisor of (10^(n + 1) + 1), and we are looking for the smallest f that starts with a 3.

      f.g = 10^(n + 1) + 1

      and f is an n digit number that starts with 3, so g = 26 .. 33.

      This Python program runs in 49ms.

      Run: [ @repl.it ]

      from enigma import irange, inf, printf
      
      def solve():
        # consider n digit fillings
        x = 101
        for n in irange(1, inf):
          # f is an n digit divisor of x
          for g in irange(33, 26, step=-1):
            (f, r) = divmod(x, g)
            if r == 0:
              yield f
          x *= 10
          x -= 9
      
      for f in solve():
        printf("f = {f}")
        break
      

      Solution: The smallest filling beginning with 3 is: f = 3448275862069.

      Where: 29f = 10^14 + 1.

      So we see why the simple program was taking so long. (In the end it took 32 minutes).

      In fact there is a family of filling numbers that start with 3 that take the form:

      344827586206 [8965517241379310344827586206] 9

      where the section in brackets can be included 0 or more times, to give fillings with length (13 + 28k) digits.

      We can adapt the program to generate all filling numbers without the restriction that the leading digit is 3.

      from enigma import irange, inf, match, printf
      
      # generate "filling" numbers
      def filling():
        # consider n digit fillings
        x = 101
        for n in irange(1, inf):
          # f is an n digit divisor of x
          M = x // 10
          for g in irange(101, 11, step=-1):
            (f, r) = divmod(x, g)
            if r == 0 and f < M <= 10 * f:
              yield f
          x *= 10
          x -= 9
      
      for f in filling():
        printf("f = {f}")
        if match(f, '3*'): break
      

      See: OIES A116436 [ @oeis.org ]

      Like

  • Jim Randell 9:48 am on 21 June 2020 Permalink | Reply
    Tags:   

    Brain-Teaser 523 

    From The Sunday Times, 20th June 1971 [link]

    The Alphabet Cricket Club (26 playing members, every surname having a different initial letter) ran into trouble last season. The selected 1st XI consisted of those with initials A to K; the 2nd XI was to be picked from the remainder, but personal feeling had crept in. (To save space, players are referred to by initials).

    U refused to play in the same team as Z. Q said that he would not be available if either L or M was picked. P announced that he would not turn out (a) unless M was in the side, (b) if either O or W played. Z declined to play in an XI containing more than one of R, S, T. Finally, V agreed to play only with Q.

    The secretary managed to pick an XI but then a further complication arose: two of the 1st XI fell ill and two of the selected 2nd XI were taken to fill the gaps. Fortunately the secretary was still able to field a 2nd XI (which, incidentally, won, M making a century).

    Who were the two promoted to the 1st XI, and who were omitted altogether?

    [teaser523]

     
    • Jim Randell 9:49 am on 21 June 2020 Permalink | Reply

      This Python program runs in 52ms.

      Run: [ @repl.it ]

      from enigma import subsets, intersect, diff, join, printf
      
      players = "LMNOPQRSTUVWXYZ"
      
      # generate possible 2nd XI's
      def generate():
        for ps in subsets(players, size=11):
      
          # verify conditions:
      
          # "U refused to play in the same team as Z"
          if 'U' in ps and 'Z' in ps: continue
      
          # "Q said that he would not be available if either L or M was picked"
          if 'Q' in ps and ('L' in ps or 'M' in ps): continue
      
          # "P announced that he would not turn out (a) unless M was in the
          # side, (b) if either O or W played"
          if 'P' in ps and ('M' not in ps or 'O' in ps or 'W' in ps): continue
      
          # "Z declined to play in an XI containing more than one of R, S, T"
          if 'Z' in ps and len(intersect((ps, "RST"))) > 1: continue
      
          # "V agreed to play only with Q"
          if 'V' in ps and 'Q' not in ps: continue
      
          yield ps
      
      # choose two sets for the second eleven
      for (s1, s2) in subsets(generate(), size=2, select="P"):
      
        # M is in the final set
        if 'M' not in s2: continue
      
        # the two promoted are in the first but not the second
        ps = diff(s1, s2)
        if len(ps) != 2: continue
      
        # the ones who were never picked
        ns = diff(players, s1 + s2)
        printf("promoted={ps} omitted={ns} [{s1} -> {s2}]", ps=join(ps), ns=join(ns), s1=join(s1), s2=join(s2))
      
      

      Solution: Q and V were promoted. P and Z were omitted.

      The original 2nd XI was: N O Q R S T U V W X Y.

      And then Q and V were promoted to the 1st XI. L and M stepped in to take their places.

      So the actual 2nd XI was: L M N O R S T U W X Y.

      P and Z were omitted from both line-ups.

      V will play only with Q, so it makes sense that Q and V were promoted together. (Although I didn’t check that the requirements for the 2nd XI were satisfied by the new 1st XI, but in this case they would be).

      These are the only two possible line-ups allowed for the 2nd XI for the given conditions, so the one with M in must be the actual line-up.

      Like

    • John Crabtree 8:06 pm on 25 June 2020 Permalink | Reply

      Four players were initially not picked.
      From the two statements involving Z, if Z plays, U does not play and at least two of R, S and T do not play.

      The two statements involving Q may be written as:
      Q + ~Q.~V = 1
      Q.~L.~M + ~Q = 1
      Combining them gives Q.~L.~M + ~Q.~V = 1
      Either L and M do not play, or Q and V do not play, and so Z does not play,
      The statements involving P may be written as P.M.~O.~W + ~P = 1
      If P plays, Q, V, O, W and Z do not play. And so P does not play.

      And so Q and V were promoted. P and Z did not play.
      L and M were brought in to the 2nd XI as replacements.

      Like

  • Jim Randell 7:06 pm on 19 June 2020 Permalink | Reply
    Tags:   

    Teaser 3013: Arian Pen-blwydd 

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

    When I thought that my daughter was old enough to be responsible with money I gave her on her next, and all subsequent birthdays, cash amounts (in pounds) which were equal to her birthday age squared.

    On her last birthday her age was twice the number of years for which she received no such presents. I calculated at this birthday that if I had made these gifts on all of her birthdays then she would have received 15% more than she had actually received. I then decided that I would stop making the payments after her birthday when she would have received only 7.5% more if the payments had been made on all of her birthdays.

    What was the amount of the final birthday payment?

    There are now 300 puzzles available on the site.

    [teaser3013]

     
    • Jim Randell 9:43 pm on 19 June 2020 Permalink | Reply

      If she didn’t receive gifts for the first k years, then the “missing” gifts are the sum of the squares of 1 .. k. The amounts actually received are the sum of the squares of (k + 1) .. 2k.

      This Python program finds the value of k when the amount of the missing gifts is 15% of the actual amount, and then continues looking at future gifts until the amount becomes 7.5%.

      It runs in 53ms.

      Run: [ @repl.it ]

      from enigma import irange, inf, printf
      
      # solve the puzzle
      def solve():
        # consider the k years before the gifts started
        for k in irange(1, inf):
          # total before amount
          before = sum(x * x for x in irange(1, k))
          # total after amount
          after = sum(x * x for x in irange(k + 1, 2 * k))
          # before = 0.15 * after
          if not(100 * before == 15 * after): continue
          printf("k = {k}; before = {before}, after = {after}")
      
          # now add in future gifts
          future = after
          for n in irange(2 * k + 1, inf):
            future += n * n
            # before = 0.075 * future
            if not(1000 * before == 75 * future): continue
            printf("-> n = {n}; n^2 = {n2}, future = {future}", n2=n * n)
            return
      
      solve()
      

      Solution: The final gift was £ 1,764.

      The gifts started on the 18th birthday, so the “missing” gifts (years 1 – 17) would amount to £ 1,785.

      The actual gifts between ages 18 and 34 amount to £ 11,900, and 15% of £ 11,900 is £ 1,785.

      The gifts are to continue to age 42, making the total amount £ 23,800, and 7.5% of £ 23,800 is also £ 1,785.

      Which means the final gift is made on the 25th (silver) anniversary of the first gift.


      Analytically:

      (See: Enigma 1086).

      The sum of the first n squares is given by the square pyramidal numbers:

      SP(n) = n (n + 1) (2n + 1) / 6

      So the first part of the puzzle is to solve:

      SP(k) = 0.15 (SP(2k) – SP(k))
      20 SP(k) = 3 (SP(2k) – SP(k))
      23 SP(k) = 3 SP(2k)
      23k (k + 1) (2k + 1) = 6k (2k + 1) (4k + 1)
      23k + 23 = 24k + 6
      k = 17

      The second part is to solve, for n > 34:

      SP(k) = 0.075 (SP(n) – SP(k))
      3 SP(n) = 43 SP(k)
      SP(n) = 25585
      n = 42

      The required answer is then: n² = 42² = 1764.

      Like

      • Jim Randell 11:19 pm on 20 June 2020 Permalink | Reply

        Or, more simply:

        We are looking for values of n, k where:

        SP(k) = (3/43) SP(n)
        SP(2k) = (23/43) SP(n)

        This Python program runs in 51ms.

        Run: [ @repl.it ]

        from enigma import irange, inf, div, printf
        
        # accumulate the square pyramidal numbers, map: SP[n] -> n
        d = dict()
        x = 0
        for n in irange(1, inf):
          # calculate: x = SP(n)
          x += n * n
          d[x] = n
          # can we find a corresponding y = SP(k)?
          y = div(x * 3, 43)
          k = d.get(y, None)
          if k is None: continue
          # and verify z = SP(2k)
          z = div(x * 23, 43)
          k2 = d.get(z, None)
          if k2 is None or k2 != k * 2: continue
          printf("n^2={n2} [n={n} k={k}; SP[{k}]={y} SP[{k2}]={z} SP[{n}]={x}]", n2=n * n)
          break
        

        Like

  • Jim Randell 7:12 am on 18 June 2020 Permalink | Reply
    Tags:   

    Brainteaser 1819: Early bath 

    From The Sunday Times, 27th July 1997 [link]

    There are 20 teams in one country’s premier league. They each play each other once in the first half of the season, and then they each play each other a second time in the rest of the season. Each team plays each Saturday of the season, earning three points for a win and one point for a draw. At the end of the season the bottom three teams are relegated and the top team wins the league championship.

    Last season was the most boring ever. It was possible to determine the relegated teams well before the end of the season. In fact it would be impossible in any season to be able to determine the three relegated teams in fewer weeks.

    Three further Saturdays after the relegations were determined the league championship was also determined when the league leaders were in a 0-0 draw and then found that they were unassailable. There were great celebrations that night.

    At that time, how many points did the current top two teams have?

    This puzzle was included in the book Brainteasers (2002, edited by Victor Bryant). The puzzle text above is taken from the book.

    [teaser1819]

     
    • Jim Randell 7:12 am on 18 June 2020 Permalink | Reply

      After a tortuous chain of reasoning we arrive at the answer:

      In the first half of the season there are C(20, 2) = 190 matches, and then another 190 in the second half of the season. Each team plays 19 matches in the first half of the season, and another 19 matches in the second half of the season. The season lasts 38 weeks, with 10 matches played each week.

      At some point there are 3 teams doomed to relegation, as they cannot possibly catch up with any of the remaining 17 teams.

      Suppose in the first half of the tournament there are three teams that lose all their matches, except the matches they play amongst themselves, which are drawn.

      Each of the three doomed teams has only 2 points (from their draws with the other two doomed teams). If all the other 187 matches were won outright there are 187×3 = 561 points to distribute between the remaining 17 teams. This gives an average of 33 points per team. But, if one of the doomed teams were to win all their matches in the second half of the tournament they would end up with 2 + 3×19 = 59 points, so their relegation is not guaranteed by the end of the first half of the tournament.

      If we carry on for k weeks into the second half of the tournament, with each doomed team losing each of their matches, and each of the other matches being won, then how many weeks is it before enough points are accumulated, so that each of the 17 remaining teams are out of reach?

      There are (19 – k) weeks remaining and a doomed team could win all their remaining matches, so they would end with 2 + 3(19 – k) = 59 – 3k points.

      And the total number of points to be shared between the 17 remaining teams would be: 561 + 30k.

      This can happen when:

      (561 + 30k) / 17 > 59 – 3k
      561 + 30k > 1003 – 51k
      81k > 442
      k > 5.46…

      i.e. after the 6th week of the second half of the tournament, at the earliest.

      There would then be 13 weeks remaining, so a doomed team that had a sudden change of fortune could finish with 2 + 3×13 = 41 points. But by that stage in the tournament 561 + 30×6 = 741 points could have been scored by the remaining 17 teams, which is enough for each of them to have accumulated at 43 points each. So the doomed teams can indeed be doomed to relegation.

      Now after three more weeks, i.e. after the 9th week of the second half of the tournament, with 10 weeks remaining, the championship was determined. So the team with the most points must be more than 30 points ahead of the next highest team.

      If we go back to 6th week of the second half of the tournament, then 16 of the 17 non-doomed teams could have 42 points, and the other team could have 69 points. So they are 27 points ahead.

      If they win the following 2 weeks, and the week after that they draw (as we are told in the puzzle text), then after the 9th week they have 76 points, and in order to be unassailable the next highest team can have no more than 45.

      So now we need to make sure none of the other 16 teams can get more than 45 points by the end of week 9. An easy way is to suppose all the matches apart from the ones involving the future champions are drawn.

      Then at the end of the 7th week, the best any of the 16 challengers can do is 43 points. The future champions have 72 points, and there are 12 weeks remaining, so they are assailable.

      At the end of the 8th week, the best any of the challengers can do is 44 points. The future champions have 75 points, and there are 11 weeks remaining, so they are still assailable.

      At the end of the 9th week, the best any of the challengers can do is 45 points. The future champions have 76 points, and there are 10 weeks remaining, so they are now unassailable.

      So this is a viable scenario for the puzzle.

      Solution: The top team had 76 points, and the next highest team had 45 points.

      Like

      • John Crabtree 5:14 pm on 19 June 2020 Permalink | Reply

        This teaser just works. After 6 weeks of the second half, 16 teams have 42 points and one has 69, ie a total of 741 for those teams and the maximum possible.

        Like

  • Jim Randell 8:42 am on 16 June 2020 Permalink | Reply
    Tags:   

    Teaser 2662: Number please 

    From The Sunday Times, 29th September 2013 [link]

    I finally got through to the operator of a large company and asked to be connected to an appropriate department. He tried eight different extension numbers before then finding the correct one. The eight numbers were 1933, 2829, 3133, 4630, 5089, 5705, 6358 and 6542. Curiously, each of these wrong numbers did have at least one correct digit of the correct extension in the correct position!

    What was the correct extension number?

    [teaser2662]

     
    • Jim Randell 8:42 am on 16 June 2020 Permalink | Reply

      Here is a recursive program that starts with unassigned digits in all positions, and then at each step looks for a number that doesn’t already match and uses it to fill out one of the unassigned digits. It runs in 53ms.

      Run: [ @repl.it ]

      from enigma import join, printf
      
      # find sequences that match ns in at least one position
      # ds - candidate digits ('?' for unassigned)
      # ns - remaining numbers to check
      def solve(ds, ns):
        # are we done?
        if not ns:
          yield join(ds)
        else:
          # consider the digits of the next number
          ms = list(zip(ds, ns[0]))
          # if any digits already match move on to the next one
          if any(a == b for (a, b) in ms):
            yield from solve(ds, ns[1:])
          else:
            # set one of the unassigned digits
            for (i, (a, b)) in enumerate(ms):
              if a == '?':
                ds_ = list(ds)
                ds_[i] = b
                yield from solve(ds_, ns[1:])
      
      # numbers provided
      numbers = '1933 2829 3133 4630 5089 5705 6358 6542'.split()
      
      # solve the puzzle, starting with 4 ?'s
      for n in solve('????', numbers):
        printf("number = {n}")
      

      Solution: The correct extension number is 6739.


      A brute force search of all possible extension numbers is shorter, and only slightly slower:

      from enigma import subsets, join, printf
      
      # the numbers tried (each has at least one correct digit in the correct position)
      numbers = '1933 2829 3133 4630 5089 5705 6358 6542'.split()
      
      # consider digits for the actual number
      for ds in subsets("0123456789", size=4, select="M"):
        if all(any(a == b for (a, b) in zip(ds, n)) for n in numbers):
          printf("number = {n}", n=join(ds))
      

      Like

  • Jim Randell 12:18 pm on 14 June 2020 Permalink | Reply
    Tags: by: Peter G Chamberlain   

    Teaser 2655: Sudoprime 

    From The Sunday Times, 11th August 2013 [link]

    The grid shows a cross-figure with two of its digits given. The eleven answers (five of them being “across” and the other six “down”) are all different prime numbers with no leading zeros. No digit appears more than once in any row, column or main diagonal.

    What are the two largest of the eleven primes?

    [teaser2655]

     
    • Jim Randell 12:19 pm on 14 June 2020 Permalink | Reply

      See also: Enigma 1730, Enigma 1740, Enigma 1755.

      I used the [[ SubstitutedExpression() ]] solver from the enigma.py library to solve this puzzle. The condition that there are no repeated digits in the rows, columns or diagonals can be expressed using the [[ --distinct ]] parameter, which lets us specify multiple groups of symbols, where none of the groups may contain repeated digits.

      The following run file executes in 93ms.

      Run: [ @repl.it ]

      #!/usr/bin/env python -m enigma -r
      
      SubstitutedExpression
      
      #
      #  A # # # B
      #  C D # E F
      #  # G H I #
      #  J K # L M
      #  N # # # P
      #
      
      # the two values we are given
      --assign="G,8"
      --assign="N,7"
      
      # the 11 answers are all different prime numbers
      "is_prime(AC)"
      "is_prime(BF)"
      "is_prime(CD)"
      "is_prime(EF)"
      "is_prime(JK)"
      "is_prime(LM)"
      "is_prime(JN)"
      "is_prime(MP)"
      "all_different(AC, BF, CD, EF, JK, LM, JN, MP)"
      
      "is_prime(DGK)"
      "is_prime(EIL)"
      "is_prime(GHI)"
      "all_different(DGK, EIL, GHI)"
      
      # no digit appears more than once in any row, column, or main diagonal
      --distinct="AB,CDEF,GHI,JKLM,NP,ACJN,DGK,EIL,BFMP,ADHLP,NKHEB"
      
      # answer is the two largest primes
      --answer="ordered(DGK, EIL, GHI)[1:]"
      
      # suppress verbose output
      --template=""
      

      Solution: The two largest primes are: 821, 983.

      The completed grid looks like this:

      Like

    • GeoffR 3:21 pm on 14 June 2020 Permalink | Reply

      % A Solution in MiniZinc - same grid as Jim
      include "globals.mzn";
      
      var 1..9:A; var 1..9:B; var 1..9:C; var 1..9:D; var 1..9:E; 
      var 1..9:F; var 1..9:G; var 1..9:H; var 1..9:I; var 1..9:J; 
      var 1..9:K; var 1..9:L; var 1..9:M; var 1..9:N; var 1..9:P; 
      
      % Given values
      constraint G == 8 /\ N == 7;
      
      % Rows
      var 11..97:CD = 10*C + D; 
      var 11..97:EF = 10*E + F; 
      var 11..97:JK = 10*J + K; 
      var 11..97:LM = 10*L + M; 
      var 101..997:GHI = 100*G + 10*H + I;
      % Columns
      var 11..97:AC = 10*A + C; 
      var 11..97:JN = 10*J + N; 
      var 101..997:DGK = 100*D + 10*G + K; 
      var 101..997:EIL = 100*E + 10*I + L; 
      var 11..97:BF = 10*B + F; 
      var 11..97:MP = 10*M + P; 
      
      predicate is_prime(var int: x) = 
      x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) 
      ((i < x) -> (x mod i > 0));
      
      % The eleven answers are all prime numbers
      constraint is_prime(CD) /\ is_prime(EF) /\ is_prime(JK) /\ is_prime(LM)
      /\ is_prime(GHI) /\ is_prime(AC) /\ is_prime(JN) /\ is_prime(DGK)
      /\ is_prime(EIL) /\ is_prime(BF) /\ is_prime(MP);
      
      % All the prime numbers are different
      constraint all_different([CD,EF,JK,LM,GHI,AC,JN,DGK,EIL,BF,MP]);
      
      % Top and bottom rows have different digits
      constraint A != B /\ N != P;
      
      % Other rows have different digits
      constraint all_different([C,D,E,F]) /\ all_different([G,H,I])
      /\ all_different([J,K,L,M]);
      
      % All the columns have different digits
      constraint all_different([A,C,J,N]) /\ all_different([D,G,K])
      /\ all_different([E,I,L]) /\ all_different([B,F,M,P]);
      
      % The diagonals have different digits
      constraint all_different([A,D,H,L,P]) /\ all_different([B,E,H,K,N]);
      
      solve satisfy;
      
      output ["Three digit primes are : " ++ show([DGK,GHI,EIL])
      ++ "\nA, B, C, D, E, F = " ++ show([A,B,C,D,E,F])
      ++ "\nG, H, I, J, K, L = " ++ show([G,H,I,J,K,L])
      ++ "\nM, N, P = " ++ show([M,N,P]) ];
      
      % Three digit primes are : [983, 821, 617]
      % A, B, C, D, E, F = [6, 9, 1, 9, 6, 7]
      % G, H, I, J, K, L = [8, 2, 1, 4, 3, 7]
      % M, N, P = [1, 7, 3]
      % ----------
      % ==========
      % Grid solution
      % 6 # # # 9
      % 1 9 # 6 7
      % # 8 2 1 #
      % 4 3 # 7 1
      % 7 # # # 3
      
      
      
      

      Like

  • Jim Randell 4:48 pm on 12 June 2020 Permalink | Reply
    Tags:   

    Teaser 3012: Number blind rage 

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

    After school, angry at getting “50 lines”, I kicked my satchel around. Impacts made my 11-digit calculator switch on. An 11-digit number was also entered and the display was damaged. Strangely, I found “dYSCALCULIA” displayed and saved this to memory (as shown).

    After various tests I confirmed that all arithmetic operations were correct and the decimal point would appear correctly if needed. No segments were permanently “on”, two digits were undamaged, and for the other digits, overall, several segments were permanently “off”.

    Retrieving “dYSCALCULIA”, I divided it by 9, then the result by 8, then that result by 7, then that result by 6. No decimal point appeared and the last result (at the right-hand side of the display) had three digits appearing as numerals.

    What number was “dYSCALCULIA”?

    [teaser3012]

     
    • Jim Randell 9:07 pm on 12 June 2020 Permalink | Reply

      I used the standard set of digits (as illustrated in Enigma 1701).

      This Python program runs in 90ms.

      from itertools import product
      from enigma import join, div, printf
      
      # normal digits
      normal = "0123456789"
      
      # map digits to illuminated segments, arranged as:
      #
      #   0
      # 1   2
      #   3
      # 4   5
      #   6
      #
      # map digits to segments
      f = lambda *ss: frozenset(ss)
      seg = {
        # normal digits
        '0': f(0, 1, 2, 4, 5, 6),
        '1': f(2, 5),
        '2': f(0, 2, 3, 4, 6),
        '3': f(0, 2, 3, 5, 6),
        '4': f(1, 2, 3, 5),
        '5': f(0, 1, 3, 5, 6),
        '6': f(0, 1, 3, 4, 5, 6), # or could be (1, 3, 4, 5, 6)
        '7': f(0, 2, 5), # or could be (0, 1, 2, 5)
        '8': f(0, 1, 2, 3, 4, 5, 6),
        '9': f(0, 1, 2, 3, 5, 6), # or could be (0, 1, 2, 3, 5)
        # malformed digits
        'a': f(0, 1, 2, 3, 4, 5),
        'c': f(0, 1, 4, 6),
        'd': f(2, 3, 4, 5, 6),
        'l': f(1, 4, 6),
        'u': f(1, 2, 4, 5, 6),
      }
      # map segments to normal digits
      norm = dict((seg[k], k) for k in normal)
      
      # the display
      display = "d45calcul1a"
      
      # compute possible replacement (superset) digits for the symbols
      r = dict((k, list(d for d in normal if seg[d].issuperset(seg[k]))) for k in set(display))
      
      # choose possible replacement digits for the symbols
      for ds in product(*(r[x] for x in display)):
        if ds[0] == '0': continue
        # two of the digits are unaffected
        if sum(x == y and x in normal for (x, y) in zip(display, ds)) < 2: continue
        # make the number
        n = int(join(ds))
        # and the result
        s = div(n, 9 * 8 * 7 * 6)
        if s is None: continue
        # remove broken segments from the result
        # x = original display, y = original digit, z = result digit
        rs = list(
          norm.get(seg[z].difference(seg[y].difference(seg[x])), '?')
            for (x, y, z) in zip(display[::-1], ds[::-1], str(s)[::-1])
        )
        # there should be 3 normal digits
        if len(rs) - rs.count('?') != 3: continue
        # output solution
        printf("{n} -> {s} -> {rs}", rs=join(rs[::-1]))
      

      Solution: dYSCALCULIA = 84588800688.

      The digits displaying 4 and 5 must be the undamaged ones.

      So the segments that are definitely broken are as shown below:

      There are 22 segments that are definitely broken, and a further 3 that we cannot determine if they are broken or not.

      The result of dividing the number by 9×8×7×6 = 3024 is 27972487, which would look something like this:

      (Only showing the segments that we definitely know to be broken, there are two segments shown lit that may be broken).

      The 2nd digit (7) displays as a 7. The 7th digit (8) displays as a 1. The 8th digit (7) displays as a 7.

      Like

  • Jim Randell 11:18 am on 11 June 2020 Permalink | Reply
    Tags: by: Ann Kindersley   

    Brain-Teaser 522 

    From The Sunday Times, 13th June 1971 [link]

    The other day I noticed some strange coincidences about the telephone numbers of my three friends.

    Each number reads the same from left to right and vice versa. The first and third digit formed the owner’s age, as did the sum of all the digits of his number and, furthermore, his number was divisible by his age.

    What were my friends’ ages?

    [teaser522]

     
    • Jim Randell 11:20 am on 11 June 2020 Permalink | Reply

      Assuming the ages cannot have a leading zero (which means the phone numbers can’t either) gives us a unique solution to the puzzle.

      This Python program uses the [[ SubstitutedExpression() ]] solver from the enigma.py library to try 3-, 4- and 5-digit numbers satisfying the required conditions. It runs in 54ms.

      Run: [ @repl.it ]

      from enigma import sprintf as f, join, SubstitutedExpression, subsets, all_different, printf
      
      # alphametic forms for possible palindromic phone numbers
      numbers = [ 'ABA', 'ABBA', 'ABCBA' ]
      
      # collect possible (number, age) solutions
      ss = list()
      
      # consider possible phone numbers
      for n in numbers:
        # age is 1st and 3rd digit
        a = n[0] + n[2]
        
        exprs = [
          # sum of digits is the same as age
          f("{s} = {a}", s=join(n, sep=" + ")),
          # the number itself is divisible by the age
          f("{n} % {a} = 0"),
        ]
      
        # solve the alphametic expressions
        p = SubstitutedExpression(exprs, distinct="", answer=f("({n}, {a})"))
        for (_, ans) in p.solve(verbose=0):
          ss.append(ans)
      
      # choose three solutions with different ages
      for (A, B, C) in subsets(ss, size=3):
        if not all_different(A[1], B[1], C[1]): continue
        printf("A={A} B={B} C={C}")
      

      Solution: The ages are: 21, 23, 27.

      The corresponding phone numbers are: 28182, 28382, 28782.

      These are the only three solutions for 5-digit phone numbers, and there are no solutions for 3- or 4-digit phone numbers.

      Like

  • Jim Randell 9:33 am on 9 June 2020 Permalink | Reply
    Tags: by: Ernest J Luery,   

    Brain-Teaser 521 

    From The Sunday Times, 6th June 1971 [link]

    There were six. Messrs. Butcher, Carpenter, Draper, Farmer, Grocer and Miller,  who shared the fire-watching on Friday nights — three this week, three the next. By occupation they were (not necessarily respectively) a butcher, a carpenter, a draper, a farmer, a grocer and a miller.

    Incidents were few and far between, until that Saturday morning when they found the “log” book signed by the Acting Deputy Assistant something or other, as follows: “All three present and fast asleep”.

    Something had to be done about it: they decided to watch, to play whist, and to keep awake in the future. It was arranged thus: four did duty this week, next week two stood down and two others came in, and so on. Each did two turns in three weeks.

    On the first Friday the carpenter, the draper, the farmer and the miller watched. Next week Mr Carpenter, Mr Draper, Mr Farmer and Mr Grocer played. On the third occasion Mr Butcher played against Mr Grocer, Mr Farmer against the butcher, and the miller against the draper. Each night the four cut for partners and kept them till morning.

    If Mr Carpenter’s occupation is the same as the name of the one whose occupation is the same as the name of the one whose occupation is the same as the one whose occupation is the same as the name of the miller:

    What is Mr Miller’s occupation?

    As presented this puzzle has no solutions. In the comments I give a revised version that does have a unique answer.

    [teaser521]

     
    • Jim Randell 9:33 am on 9 June 2020 Permalink | Reply

      I thought the tricky bit in this puzzle would be detangling the long obfuscated condition at the end (and decide if there was a “the name of” missing from it). But it turns out we can show that there are no solutions before we get that far, so the puzzle is flawed.

      In week 3 we have the following pairs (Mr Butcher + Mr Grocer), (Mr Farmer + the butcher), (the miller + the draper).

      But there are only four people (i.e. two pairs), so one of the pairs is repeated. The middle one doesn’t overlap with either of the outer two, so the outer two must refer to the same pair. i.e. (Mr Butcher + Mr Grocer) = (the miller + the draper).

      In week 2 we had Mr Carpenter, Mr Draper, Mr Farmer and Mr Grocer. And Mr Farmer and Mr Grocer stayed on for week 3, which means they can’t have done week 1.

      The jobs missing from week 1 are the butcher and the grocer, so: (Mr Farmer + Mr Grocer) = (the butcher + the grocer).

      But Mr Grocer cannot be one of (the miller + the draper) and also one of (the butcher + the grocer).

      So the described situation is not possible.


      However if we change the names in the second week to match the jobs from the first week (which I think makes for a more pleasing puzzle), and also insert the missing “the name of” into the final obfuscated condition we get the following revised puzzle:

      On the first Friday the carpenter, the draper, the farmer and the miller watched. Next week Mr Carpenter, Mr Draper, Mr Farmer and Mr Miller played. On the third occasion Mr Butcher played against Mr Grocer, Mr Farmer against the butcher, and the miller against the draper. Each night the four cut for partners and kept them till morning.

      If Mr Carpenter’s occupation is the same as the name of the one whose occupation is the same as the name of the one whose occupation is the same as the name of the one whose occupation is the same as the name of the miller:

      What is Mr Miller’s occupation?

      Then we get a puzzle that does have solutions (although not the same as the published solution).

      The following Python program runs in 54ms.

      Run: [ @repl.it ]

      from enigma import irange, subsets, multiset, map2str, printf
      
      # labels for the names and jobs
      labels = (B, C, D, F, G, M) = irange(0, 5)
      
      # check the schedule for the 3 weeks
      def check(w1, w2, w3):
        m = multiset()
        for w in (w1, w2, w3):
          w = set(w)
          # 4 different people each week
          if len(w) != 4: return False
          m.update_from_seq(w)
        # each person does 2 duties over the 3 weeks
        return all(v == 2 for v in m.values())
      
      # map: job -> name
      for n in subsets(labels, size=len, select="P"):
      
        # Week 1 = carpenter, draper, farmer, miller
        w1 = [n[C], n[D], n[F], n[M]]
        # Week 2 = Carpenter, Draper, Farmer, Miller
        w2 = [C, D, F, M] # NOT: [C, D, F, G]
        # Week 3 = Butcher + Grocer, Farmer + butcher, miller + draper
        # so: Butcher + Grocer = miller + draper
        if not(set([B, G]) == set([n[M], n[D]])): continue
        w3 = [B, G, F, n[B]]
      
        if not check(w1, w2, w3): continue
      
        # "Mr Carpenter's occupation is the same as the name of the one
        # whose occupation is the same as the name of the one whose
        # occupation is the same as the [name of] one whose occupation is
        # the same as the name of the miller"
        if not(n[n[n[n[n[M]]]]] == C): continue
      
        # output the map
        names = ("Butcher", "Carpenter", "Draper", "Farmer", "Grocer", "Miller")
        jobs = list(x.lower() for x in names)
        printf("{s}", s=map2str(((names[n], j) for (n, j) in zip(n, jobs)), sep="; ", enc=""))
      

      Solution: Mr Miller is the carpenter.

      There are three ways to assign the jobs to the names:

      Butcher=draper; Carpenter=butcher; Draper=farmer; Farmer=grocer; Grocer=miller; Miller=carpenter
      Butcher=miller; Carpenter=butcher; Draper=farmer; Farmer=grocer; Grocer=draper; Miller=carpenter
      Butcher=miller; Carpenter=farmer; Draper=butcher; Farmer=grocer; Grocer=draper; Miller=carpenter

      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
Create your website at WordPress.com
Get started
%d bloggers like this: