Tagged: by: Ptolemaeus Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 10:38 am on 18 July 2021 Permalink | Reply
    Tags: by: Ptolemaeus   

    Brain-Teaser 40: Christmas greetings 

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

    The greetings above quite literally sum up my festive feelings, for they are, in fact, two simple addition sums in which each  of which each digit has been replaced by an “Adventitious” letter. You are to replace each letter by the digit it stands for.

    Having found the value of a letter in one of the sums, you  must not assume that the letter necessarily retains that same  value in the other sum. The two examples are quite  independent apart from the one condition that the difference between the sum of the digits in MERRY and the sum of the digits in XMAS must be made as small as possible.

    As I have already said — A Very Very Merry Xmas To One And All.

    [teaser40]

     
    • Jim Randell's avatar

      Jim Randell 10:40 am on 18 July 2021 Permalink | Reply

      The following Python program uses the [[ SubstitutedSum ]] solver from the enigma.py library to solve the alphametic sums, and then finds minimal distance solutions.

      It runs in 76ms.

      Run: [ @replit ]

      from itertools import product
      from enigma import SubstitutedSum, group, unpack, printf
      
      # sum 1: group solutions by M+E+R+R+Y
      p1 = SubstitutedSum(["A", "VERY", "VERY"], "MERRY")
      s1s = group(p1.solve(verbose=0), by=(lambda s: sum(s[x] for x in 'MERRY')))
      
      # sum 2: group solutions by X+M+A+S
      p2 = SubstitutedSum(["XMAS", "TOONE"], "ANDALL")
      s2s = group(p2.solve(verbose=0), by=(lambda s: sum(s[x] for x in 'XMAS')))
      
      # choose the pair with the minimal distance
      (k1, k2) = min(product(s1s.keys(), s2s.keys()), key=unpack(lambda x, y: abs(x - y)))
      
      # output solutions
      for (s1, s2) in product(s1s[k1], s2s[k2]):
        printf("(1) {s1}; (2) {s2}",
          s1=p1.substitute(s1, p1.text),
          s2=p2.substitute(s2, p2.text),
        )
      

      Solution: (i) 8 + 7492 + 7492 = 14992; (ii) 7618 + 95504 = 103122.


      The first alphametic sum has 2 solutions:

      2 + 7498 + 7498 = 14998 | M+E+R+R+Y = 31
      8 + 7492 + 7492 = 14992 | M+E+R+R+Y = 25

      The second alphametic sum has 2 solutions:

      7614 + 95508 = 103122 | X+M+A+S = 18
      7618 + 95504 = 103122 | X+M+A+S = 22

      And the minimum distance is between M+E+R+R+Y = 25, and X + M + A + S = 22.

      Like

    • GeoffR's avatar

      GeoffR 4:58 pm on 18 July 2021 Permalink | Reply

      % A Solution in MiniZinc 
      include "globals.mzn";
      
      % 1st sum:  A + VERY + VERY == MERRY
      var 1..9:A; var 1..9:V; var 0..9:E;
      var 1..9:R; var 0..9:Y; var 1..9:M;
      
      constraint all_different([A, V, E, R, Y, M]);
      
      var 1000..9999:VERY = 1000*V + 100*E + 10*R + Y;
      var 10000..99999:MERRY = 10000*M + 1000*E + 110*R + Y;
      
      constraint A + VERY + VERY == MERRY;
      
      % 2nd Sum:  XMAS + TOONE = ANDALL
      % using lower case letters to be different from 1st equation
      var 1..9:x; var 0..9:m; var 1..9:a; var 0..9:s; var 1..9:t;
      var 0..9:o; var 0..9:n; var 0..9:e; var 0..9:d; var 0..9:l;
      
      constraint all_different ([x, m, a, s, t, o, n, e, d,l]);
      
      var 1000..9999:xmas = 1000*x + 100*m + 10*a + s;
      var 10000..99999:toone = 10000*t + 1100*o + 10*n + e;
      var 100000..999999:andall = 100000*a + 10000*n + 1000*d + 100*a + 11*l;
      
      constraint xmas + toone == andall;
      
      % Minimise difference in sum of digits between MERRY and XMAS
      solve minimize(abs(M + E + R + R + Y - x - m - a - s));
      
      output ["Sum 1 is " ++ show(A) ++ " + " ++ show(VERY) ++ " + " 
      ++ show(VERY) ++ " = " ++ show(MERRY) ++ " " ++ "\n" ++ 
      "Sum 2 is " ++show(xmas) ++ " + " ++ 
      show(toone) ++ " = " ++ show(andall)
      ++ "\n" ++ "Difference of sum of digits between MERRY and XMAS  = "   
      ++ show(M + E + R + R + Y - x - m - a - s) ];
      
      % Sum 1 is 8 + 7492 + 7492 = 14992 
      % Sum 2 is 7614 + 95508 = 103122
      % Difference of sum of digits between MERRY and XMAS  = 7
      % ----------
      % Sum 1 is 8 + 7492 + 7492 = 14992 
      % Sum 2 is 7618 + 95504 = 103122
      % Difference of sum of digits between MERRY and XMAS  = 3  << answer
      % ----------
      % ==========
      
      

      Like

  • Unknown's avatar

    Jim Randell 8:57 am on 28 March 2021 Permalink | Reply
    Tags: by: Ptolemaeus   

    Brain-Teaser 28: Army squares 

    From The Sunday Times, 1st October 1961 [link]

    Kublis Ghen was very particular about his army formations. Originally, each company consisted of a certain number of men who could be drawn up in the form of a perfect square. Nor was this all, for when the companies were drawn up one behind the other (each company being spread out to form a single row) the entire army itself thus constituted a square. It was an army to be proud of, but when the great conqueror determined to attack Thalbazzar he was not content, and summoned his chief of staff: “My army is not big enough”, he declared. “Double it”.

    Knowing the temper of his master, the chief of staff saw to it that the size of the army was doubled — exactly. But an unforeseen difficulty arose: the army could no longer form a perfect square — there was just one man too many.

    “Kill him”, ordered the conqueror on hearing the news, and the offending supernumerary was duly dispatched, so that the army marched into battle in the form of a square though, of course, its company formations had been completely disorganised.

    A million men did Kublis Ghen
    Against Thalbazzar thow;

    says the poet, but that is an exaggeration.

    How many men were in the army that Kublis Ghen threw against Thalbazzar?

    [teaser28]

     
    • Jim Randell's avatar

      Jim Randell 8:58 am on 28 March 2021 Permalink | Reply

      If there are k² men in a company, then in order to form a square when each company is in a line there must be as many companies as there are men in a company. So (k²)² men in total.

      When the army size is doubled, the remaining number is 1 more than a square:

      2(k^4) − 1 = n^2

      We can consider possible values of k until (2(k^4) − 1) exceeds 1 million (at k = 27).

      This Python program runs in 49ms.

      Run: [ @replit ]

      from enigma import (irange, inf, is_square, printf)
      
      # consider k values
      for k in irange(1, inf):
        n = 2 * pow(k, 4) - 1
        if n > 1000000: break
        if is_square(n):
          printf("k={k} -> n={n}")
      

      Solution: There were 57121 men in the army marching into battle.


      Each company consisted of 13² = 169 men, which could be formed into a 13×13 square or a 1×169 line.

      The 169 companies can then be formed into a 169×169 square = 28561 men in total.

      The army size is doubled to 57122 = 239² + 1. And one of these is removed.

      So, the army of 57121 men marched into battle as a 239×239 square.

      Like

    • John Crabtree's avatar

      John Crabtree 4:34 pm on 30 March 2021 Permalink | Reply

      2x^2 = y^2 + 1 where x is square. y/x is an approximation to sqrt(2).
      For 2x^2 = y^2 +/- 1, y/x = 1/1, 3/2, 7/5, 17/12, 41/29, 99/70, 239/169, 577/408, 1393/985 etc
      x(k) = x(k-1) + y(k-1). and y(k) = 2 * x(k-1) + y(k-1).
      169 = 13^2, and so there were 239^2 = 57121 men in the army.
      As a check, 2 * 169^2 = 239^2 + 1

      Like

  • Unknown's avatar

    Jim Randell 9:26 am on 7 February 2021 Permalink | Reply
    Tags: by: Ptolemaeus   

    Brain-Teaser 20: The kite 

    From The Sunday Times, 6th August 1961 [link]

    Some problems that look simple enough at first can prove to be remarkably tricky. Consider, for instance, the kite pictured above. The shaded areas are squares of equal size, the sides of each square being 15 inches. The width of the kite from A to B is exactly 42 inches.

    What is the length of the kite from C to D?

    [teaser20]

     
    • Jim Randell's avatar

      Jim Randell 9:29 am on 7 February 2021 Permalink | Reply

      The figure is a right kite [ @wikipedia ], so is composed of 2 identical right-angled triangles joined along their common hypotenuse CD (which is the length we wish to determine).

      Writing: AC = BC = a, and AD = BD = b, then the value we wish to determine, CD, is:

      CD = √(a² + b²)

      We are told the other diagonal, AB, has length 42, hence:

      42 = 2ab / √(a² + b²)
      21√(a² + b²) = ab

      And the sides of the squares that run from the centre to the edges of the kite are radii of the incircle, so:

      15 = ab / (a + b)

      Writing: x = ab, y = a + b, we get:

      15 = x / y
      x = 15y
      x² = 225y²

      Also:

      a² + b² = (a + b)² − 2ab = y² − 2x

      So:

      441(y² − 2x) = x²
      441(y² − 30y) = 225y²
      216y² = 13230y
      4y = 245
      y = 245 / 4
      x = 3675 / 4

      So the value of CD is:

      CD = √(a² + b²)
      = √(y² − 2x)
      = √(30625 / 16)
      = 175 / 4

      Solution: CD = 43.75 inches.

      And the lengths of the sides of the kite are 26.25 in and 35 in.

      Like

    • John Crabtree's avatar

      John Crabtree 10:22 pm on 8 February 2021 Permalink | Reply

      Let the mid-point of AB be F, and the point where the squares meet be G
      By Pythagoras, FG = √(2 * 225 – 441) = 3
      Let z be the angle formed by GAF.
      Tan(z) = t = 3 / 21 = 1 / 7
      CD = 21 [tan(45 + z) + tan(45 – z)] = 21 [(1+t)/(1-t) + (1-t)/(1+t))
      = 21 [4/3 + 3/4] = 21 * 25/12 = 43.75 inches.
      AC = 21 * 5/4 = 26.25 in. AD = 21 * 5/3 = 35 in.

      Like

  • Unknown's avatar

    Jim Randell 4:06 pm on 6 September 2020 Permalink | Reply
    Tags: by: Ptolemaeus   

    Brain-Teaser 7: The Golden Wedding 

    From The Sunday Times, 9th April 1961 [link]

    Many years ago there lived in Addison Street four sisters, June, Alice, Mary and Dawn. In that street there lived also four young men. Harry, Graham, Richard and Tom. On a bright, spring day in 1911 each of the four sisters married the young man of her choice. Each of the four couples had children: June and Mary together had as many children as Alice.

    When all the children grew up and, in the course of time, married to become parents themselves each of them had the same number of children as there had been in his or her own family (for instance, had June borne five children, each of these five would have had five, too, and so on).

    Last week, the four original couples celebrated their Golden Wedding at a party attended by all their 170 grandchildren. Richard, who despite the fact that his was the smallest family had always been fascinated by numbers, pointed out that June and Alice together had as many grandchildren, as Mary and Dawn. He also noticed that Harry had four times as many grandchildren as Graham had children.

    Which sisters married which young men on that bright spring day in 1911?

    [teaser7]

     
    • Jim Randell's avatar

      Jim Randell 4:07 pm on 6 September 2020 Permalink | Reply

      The (children, grandchildren) pairs are of the form (n, n²).

      We know in total there are 170 grandchildren, and that (J and A) have as many grandchildren as (M and D). So each bracketed pair has 85 grandchildren in total.

      This Python program runs in 51ms.

      Run: [ @replit ]

      from enigma import (Record, irange, subsets, printf)
      
      # record for each sister: w=initial, c=children, g=grandchildren
      ss = (J, A, M, D) = tuple(Record(w=x) for x in "JAMD")
      
      # squares less than 85 (map: square -> root)
      sq = dict((n * n, n) for n in irange(0, 9))
      
      # find pairs with squares that sum to 85
      pairs = list(s for s in subsets(sq.keys(), size=2, select="M") if sum(s) == 85)
      
      # choose 4 values for the children/grandchildren of each sister
      for (x1, x2) in subsets(pairs, size=2, select="M"):
        xs = x1 + x2
        (J.g, A.g, M.g, D.g) = xs
        (J.c, A.c, M.c, D.c) = (sq[x] for x in xs) 
        # "J and M together have as many children as A"
        if not (J.c + M.c == A.c): continue
        # assign the sisters to husbands
        for (H, G, R, T) in subsets(ss, size=4, select="P"):
          # "R has the smallest family"
          if not (R.c == min(J.c, A.c, M.c, D.c)): continue
          # "H has 4 times as many grandchildren as G has children"
          if not (H.g == 4 * G.c): continue
          # output solution
          printf("H+{H.w}={H.c}+{H.g}; G+{G.w}={G.c}+{G.g}; R+{R.w}={R.c}+{R.g}; T+{T.w}={T.c}+{T.g}")
      

      Solution: The married couples are: Dawn & Harry; Alice & Graham; June & Richard; Mary & Tom.

      Dawn & Harry: 6 children; 36 grandchildren.
      Alice & Graham: 9 children; 81 grandchildren.
      June & Richard: 2 children; 4 grandchildren.
      Mary & Tom: 7 children; 49 grandchildren.

      Like

      • Jim Randell's avatar

        Jim Randell 9:52 pm on 6 September 2020 Permalink | Reply

        Manually we see that (J and A) and (M and D) both have 85 grandchildren, so they correspond to the 2 ways to represent 85 as the sum of 2 squares:

        85 = 2² + 9² = 6² + 7²

        Also (J and M) have as many children as A.

        So J has 2 children, M has 7 and A has 9, leaving D with 6.

        R has the smallest family. So:

        J & R have 2 children and 4 grandchildren.

        And H has 4 times as many grandchildren as G has children, so:

        D & H have 6 children and 36 grandchildren.
        A & G have 9 children and 81 grandchildren.

        Leaving:

        M & T have 7 children and 49 grandchildren.

        Like

    • Frits's avatar

      Frits 5:50 pm on 6 September 2020 Permalink | Reply

       
      from enigma import  SubstitutedExpression, irange, seq_all_same
      
      p = SubstitutedExpression([
          # each sister married a brother
          # so similar number of children for sisters and brothers
          "sorted([J,A,M,D]) == sorted([H,G,R,T])",
          
          # in total 170 grandchildren 
          "J*J + A*A + M*M + D*D == 170",
          "H*H + G*G + R*R + T*T == 170",
          
          #(J and A) have as many grandchildren as (M and D). 
          "J*J + A*A == M*M + D*D",
          
          # "J and M together have as many children as A"    
          "J + M = A",
          
          # "R has the smallest family"
          "min(H,G,R,T) == R", 
          
          # "H has 4 times as many grandchildren as G has children"
          "H*H == 4 * G"
         ],
          verbose=0,
          # example with 2 code functions
          answer="(J, A, M, D, H, G, R, T)",
          distinct="",
          digits=irange(1, 9),
      )
      
      sis = ['June', 'Alice', 'Mary', 'Dawn']
      bro = ['Harry', 'Graham', 'Richard',  'Tom']
      
      # Print answers
      for (_, ans) in p.solve():
        for i in range(4):
          for k in range(4,8):
            if ans[k] == ans[i]:
              print(f"{sis[i]:5} & {bro[k-4]:7}: \
      {ans[i]} children, {ans[i]*ans[i]} grandchildren")
        
      # Output:
      #
      # June  & Richard: 2 children, 4 grandchildren
      # Alice & Graham : 9 children, 81 grandchildren
      # Mary  & Tom    : 7 children, 49 grandchildren
      # Dawn  & Harry  : 6 children, 36 grandchildren
      

      Like

  • Unknown's avatar

    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's avatar

      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

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