Tagged: by: D Poulter Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 9:39 am on 26 April 2022 Permalink | Reply
    Tags: by: D Poulter   

    Brain-Teaser 690: … And two poles 

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

    In my garden, which is level, there are two vertical flagpoles and although there is little apparent difference in their respective heights I know that their actual heights are each an exact but different number of inches.

    As part of their anchoring taut wires stretch from the very top of each to the foot of the other. The crossing-point of these two wires is exactly eleven feet from the ground.

    What are the heights of the flagpoles?

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

    [teaser690]

     
    • Jim Randell's avatar

      Jim Randell 9:42 am on 26 April 2022 Permalink | Reply

      When resistors with values r1 and r2 are connected in parallel, the value of the combined resistance R is given by:

      1/R = 1/r1 + 1/r2

      (See: Teaser 3058).

      The value of R can also be calculated using the following diagram:

      Where the height of the crossing point gives the combined resistance.

      The flagpoles in the question also correspond to this diagram. Their heights being r1 and r2 and the crossing point being 11ft = 132in above the ground corresponds to R.

      So we need to find two different values whose reciprocals sum to 1/132. And the [[ reciprocals() ]] function in the enigma.py library can do this for us.

      The following Python program runs in 59ms.

      Run: [ @replit ]

      from enigma import (Accumulator, reciprocals, sprintf, printf)
      
      # find (a, b) such that 1/a + 1/b = 1/132
      # record the smallest difference (i.e. the final candidate)
      r = Accumulator(fn=min)
      for (a, b) in reciprocals(2, 132):
        # a, b must be different
        if a == b: continue
        r.accumulate_data(b - a, (a, b))
        printf("[a={a} b={b}]")
      
      # format <x> inches as "<f>ft <i>in"
      def fmt(x):
        (d, r) = divmod(x, 12)
        return sprintf("{d}ft {r}in")
      
      # output solution
      (a, b) = r.data
      printf("A = {a}; B = {b}", a=fmt(a), b=fmt(b))
      

      Solution: The heights of the flagpoles are: 21ft 1in, 23ft 0in.

      This is the solution where the flagpoles are as close as possible in height (we have: 1/253 + 1/276 = 1/132).

      But there are other candidate solutions where the difference in height is greater, e.g. the next solution would be 1/231 + 1/308 = 1/132 to give values of 19ft 3in and 25ft 8in.

      So to narrow the solution down to a single candidate we could say the flagpoles had a difference in height of less than 6ft.

      Like

    • GeoffR's avatar

      GeoffR 11:12 am on 26 April 2022 Permalink | Reply

      
      % A Solution in MiniZinc
      include "globals.mzn";
      
      % Assume Max flagpole height = 30 ft.
      var 1..360:a;
      var 1..360:b;
      
      % 1/a + 1/b = 1/132
      constraint 132 * (b + a) == a * b;
      
      % extra constraint for a single solution
      % ...the flagpoles had a difference in height of less than 6ft
      constraint a > b /\ a - b  < 72;
      
      solve minimize(a - b);
      
      output ["Heights of flagpoles = " ++ show(a) ++ 
      " and " ++ show(b) ++  " inches." ];
      
      % Heights of flagpoles = 276 and 253 inches.
      % ----------
      % ==========
      
      

      Like

  • Unknown's avatar

    Jim Randell 9:39 am on 18 May 2021 Permalink | Reply
    Tags: by: D Poulter   

    Brain-Teaser 768: Bus ticket numbers 

    From The Sunday Times, 4th April 1976 [link]

    On a recent bus journey I purchased the tickets for my wife and myself. On each was a four-figure number, and the sum of all eight digits was twenty-five.

    I remarked upon this to my wife who thereupon asked if any digit appeared more than twice in total, and whether the sum of the digits on either ticket was equal to thirteen.

    I answered both questions and my wife was able to deduce the two numbers on the tickets.

    What were they?

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

    [teaser768]

     
    • Jim Randell's avatar

      Jim Randell 9:41 am on 18 May 2021 Permalink | Reply

      If the ticket numbers are randomised then there is no solution. So I assumed that the tickets are consecutively numbered (I think the puzzle text should have stated this).

      This Python program runs in 84ms.

      Run: [ @replit ]

      from enigma import irange, tuples, nsplit, unpack, multiset, filter_unique, nconcat, printf
      
      # consider possible consecutive values for two tickets
      tickets = tuples((nsplit(n, 4) for n in irange(1, 9999)), 2)
      
      # the sum of all the digits is 25
      tickets = filter(unpack(lambda xs, ys: sum(xs) + sum(ys) == 25), tickets)
      
      # questions asked
      def q(xs, ys):
        # does any digit appear more than twice?
        ds = multiset.from_seq(xs, ys)
        q1 = any(v > 2 for v in ds.values())
        # do the digits on either ticket sum to 13?
        q2 = (sum(xs) == 13 or sum(ys) == 13)
        return (q1, q2)
      
      # the answers to the questions allow the tickets to be deduced
      ss = filter_unique(tickets, unpack(q)).unique
      
      # output solutions
      for (xs, ys) in ss:
        printf("tickets = {x}, {y}", x=nconcat(xs), y=nconcat(ys))
      

      Solution: The ticket numbers were 1299 and 1300.

      So the answers to questions were: No (no digit appears more than twice in total), and no (the digits on neither ticket sum to 13).

      For (yes, no), there are only three pairs: 0399 and 0400; 2199 and 2200; 3099 and 3100.

      For (no, yes) there are 132 pairs, and for (yes, yes) there are 273 pairs.

      Like

    • Frits's avatar

      Frits 8:25 pm on 31 May 2021 Permalink | Reply

      Doing the same (but not allowing leading zeroes) without using all the handy stuff in enigma.py.
      Some steps could have been combined.

      # convert digits to number
      d2n = lambda args: int("".join(map(str, args)))
      
      # return entries where the combination of columns <col1> and <col2> is unique
      def unique_cols(seq, col1=0, col2=1):
        return [s1 for s1 in seq 
                if len([1 for s2 in seq if s2[col1] == s1[col1] and 
                                           s2[col2] == s1[col2]]) == 1] 
       
      
      # consider possible consecutive values for two tickets
      tickets = list(zip((s := [[int(x) for x in str(n)] 
                          for n in range(1000, 10000)]), s[1:]))
       
      # the sum of all the digits is 25
      tickets = [(x, y) for (x, y) in tickets if sum(x) + sum(y) == 25]
      
      # store answers to the 2 questions
      tickets = [(any((s := x + y).count(p) > 2 for p in s),
                 sum(x) == 13 or sum(y) == 13, x, y) for (x, y) in tickets]
      
      # the answers to the questions allow the tickets to be deduced
      tickets = unique_cols(tickets)
      
      for t in tickets:
        print(f"tickets = {d2n(t[2])}, {d2n(t[3])}")
      

      Like

  • Unknown's avatar

    Jim Randell 7:48 am on 28 March 2019 Permalink | Reply
    Tags: by: D Poulter   

    Brain-Teaser 467: [Registration numbers] 

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

    There was a christening at our house last Sunday and there were three visitors’ cars in the drive.

    The car registration numbers of these three cars (disregarding any letters) each a three-digit prime number and among these numbers each of the digits 1 to 9 was used once only.

    This in itself was quite remarkable, but the sum of there three three-digit primes gave the three digit registration number of my own car.

    What were the three registration numbers of the visitors’ cars?

    This puzzle was originally published with no title.

    [teaser467]

     
    • Jim Randell's avatar

      Jim Randell 7:49 am on 28 March 2019 Permalink | Reply

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

      This run-file executes in 82ms.

      #! python -m enigma -rr
      
      SubstitutedExpression
      
      --digits="1-9"
      --answer="(ABC, DEF, GHI)"
      
      # the three 3-digit primes
      "is_prime(ABC)"
      "is_prime(DEF)"
      "is_prime(GHI)"
      
      # their sum is also a 3-digit number
      "ABC + DEF + GHI < 1000"
      
      # put them in order
      "ABC < DEF < GHI"
      

      Solution: The registration numbers are: 149, 263, 587.

      So, the setters registration number is 999.

      Like

    • GeoffR's avatar

      GeoffR 4:00 pm on 28 March 2019 Permalink | Reply

      % A Solution in MiniZinc
      include "globals.mzn";
      
      enum letters = {A, B, C, D, E, F, G, H, I};   
      array [letters] of var 1..9: v;
      
      constraint all_different (v);
      
      predicate is_prime(var int: x) = 
      x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) ((i < x) -> (x mod i > 0));
      
      var 100..999: ABC = 100*v[A] + 10*v[B] + v[C];
      var 100..999: DEF = 100*v[D] + 10*v[E] + v[F];
      var 100..999: GHI = 100*v[G] + 10*v[H] + v[I];
      var 100..999: XYZ;    % my car registration number
      
      constraint ABC + DEF + GHI == XYZ /\ GHI > DEF /\ DEF > ABC;
      
      constraint is_prime(ABC) /\ is_prime(DEF) /\ is_prime(GHI);
      
      solve satisfy;
      
      output[ "The three registration numbers of the visitors’ cars were " ++ show(ABC) 
      ++ ", " ++ show(DEF) ++ " and " ++ show(GHI) ]; 
      
      % The three registration numbers of the visitors’ cars were 149, 263 and 587
      
      
      

      Like

  • Unknown's avatar

    Jim Randell 2:05 pm on 28 February 2019 Permalink | Reply
    Tags: by: D Poulter   

    Brain-Teaser 457: [March-past] 

    From The Sunday Times, 15th February 1970 [link]

    The Duke of Teresa and Baron von Barin agreed to have a march-past of their respective men-at-arms to celebrate the wedding of the Duke’s son with Baron’s daughter. Each troop would march past in column of three (i.e. 3 men per file). The Duke has a few thousand men and the Baron about half as many.

    On the appointed day however, one of the Duke’s men could not go on parade and so the men were ordered into column of four, but 3 men were left over, whereupon they formed column of five and 4 men were left over, and this pattern of behaviour persisted as the Duke consecutively increased the number per file until all the men made an exact number of files.

    Meanwhile, the Baron has the same problem. One man reported sick and he consecutively increased the number per file and in column of four had 3 left over, column of five had 4 left over, etc., and eventually he reached a number per file that left no man spare.

    The Baron’s men proceeded to march past but the Duke was in a dilemma as each body of troops had a different number of men per file. He immediately solved this by ordering his men to form files with the same number of men as the Baron’s. This they did without any men being left over.

    How many men respectively had the Duke and the Baron on parade?

    This puzzle was originally published with no title.

    [teaser457]

     
    • Jim Randell's avatar

      Jim Randell 2:09 pm on 28 February 2019 Permalink | Reply

      The total number of men (including the indisposed man) must be able to form 3, 4, 5, … lines, if they are unable to form lines when one of them is missing, being short by one man.

      So, if we can form 3, 4, 5, … lines, the total number of men must be a multiple of 3, 4, 5, …, i.e. a multiple of lcm(3, 4, 5, …).

      This Python program looks for possible total numbers of men for the Duke D and the Baron B, and then finds the solution where the ratio D/B is closest to 2. I assumed the Duke had somewhere between 2,000 and 10,000 men. The program runs in 84ms.

      Run: [ @repl.it ]

      from itertools import count, combinations
      from collections import defaultdict
      from enigma import irange, mlcm, fdiv, Accumulator, printf
      
      # suppose the number of men (n - 1) end dividing into k equal sized lines (k > 6)
      # for all lowers numbers they are one short, so n must be a multiple of all lower numbers
      
      # minimum/maximum numbers to consider for D
      (m, M) = (2000, 10000)
      
      # record lcms up to M by k
      d = defaultdict(list)
      for k in count(7):
        n = mlcm(*irange(2, k - 1))
        if n > M: break
        d[k] = n
      
      # choose the result with D/B nearest to 2.0
      r = Accumulator(fn=(lambda x, y: (x if abs(x - 2.0) < abs(y - 2.0) else y)))
      
      # choose k's for D and B (kD < kB)
      for (kD, kB) in combinations(sorted(d.keys()), 2):
        (mD, mB) = (d[kD], d[kB])
        # the Duke has "a few thousand men"
        for D in irange(mD, M, step=mD):
          if D < m: continue
          # (D - 1) is divisible by kD and kB
          if not ((D - 1) % kD == 0 and (D - 1) % kB == 0): continue
          # the Baron "about half as many"
          for B in irange(mB, M, step=mB):
            # (B - 1) is divisible by kB
            if (B - 1) % kB != 0: continue
      
            # output the solution (the numbers on parade are B-1, D-1)
            r.accumulate_data(fdiv(D, B), (D - 1, B - 1))
            printf("kD={kD} kB={kB}, mD={mD} mB={mB}, D={D} B={B} [D/B ~ {f:.3f}]", f=fdiv(D, B))
      
      # output the solution
      (D, B) = r.data
      printf("parade: B={B}, D={D}")
      

      Solution: The Duke had 5159 men on parade. The Baron had 2519 men on parade.

      The ratio D/B is approximately 2.05.

      The Duke’s men are one man short of forming 3, 4, 5, 6 lines, but can form 7 lines (5159 = 737 × 7).

      The Baron’s men are one man short of forming 3, 4, 5, 6, 7, 8, 9, 10 lines, but can form 11 lines (2519 = 229 × 11).

      The Duke’s men can also form 11 lines (5159 = 469 × 11).

      There is a further solution where the Duke has 9779 men on parade (and the Baron still has 2519), but in this case the D/B ratio is 3.88.

      If we allow the Duke and the Baron more men then we can get the ratio closer to 2. There is a solution with D=60599 and B=30239, giving a ratio of 2.004, but it is hard to describe 60,600 men as “a few thousand”.

      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