Tagged: by: Alan Hunt Toggle Comment Threads | Keyboard Shortcuts

  • Jim Randell 1:57 pm on 15 December 2019 Permalink | Reply
    Tags: by: Alan Hunt   

    Brainteaser 1771: Lottery logic 

    From The Sunday Times, 25th August 1996 [link]

    For his weekly flutter on the National Lottery my friend has to select six of the numbers between 1 and 49 inclusive. Last week he wrote his numbers in numerical order and noticed something which he thought would interest me.

    The first three numbers written in succession, with no gaps, formed a perfect square. The remaining three, similarly combined, formed another square. He suggested I try to deduce his six numbers.

    Fortunately I knew his largest number was even and that he always chose one single-digit number.

    Which numbers had he selected?

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

    [teaser1771]

     
    • Jim Randell 1:58 pm on 15 December 2019 Permalink | Reply

      This Python program runs in 74ms.

      Run: [ @repl.it ]

      from itertools import product
      from enigma import irange, nsplit, printf
      
      # consider 5- and 6- digit squares
      (n5s, n6s) = (list(), list())
      for i in irange(102, 689):
        n = i * i
        # split the square into 3 2-digit numbers
        (a, b, c) = nsplit(n, 3, 100)
        # the numbers must be increasing, less than 50
        if not(a < b < c < 50): continue
        if a < 10:
          # the first set has exactly one 1-digit number
          if not(b < 10): n5s.append((a, b, c))
        else:
          # the second set ends with an even number
          if c % 2 == 0: n6s.append((a, b, c))
      
      # choose two groups of three
      for (n5, n6) in product(n5s, n6s):
        # are the groups in order?
        if not(n5[-1] < n6[0]): continue
        # output the numbers
        printf("{s}", s=n5 + n6)
      

      Solution: The numbers chosen are: 2, 13, 16, 21, 34, 44.

      We have: 21316 = 146², 213444 = 462².

      Like

    • GeoffR 10:21 am on 16 December 2019 Permalink | Reply

      
      % A Solution in MiniZinc
      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 10..49:BC = 10*B + C; 
      var 10..49:DE = 10*D + E;
      var 10..49:FG = 10*F + G;
      var 10..49:HI = 10*H + I;
      var 10..49:JK = 10*J + K;
      
      % Lottery numbers are A, BC, DE, FG, HI, and JK
      constraint all_different ([BC, DE, FG, HI, JK]);
      
      % He wrote his numbers in numerical order
      constraint increasing([BC, DE, FG, HI, JK]);
      
      % Largest lottery number was even
      constraint JK mod 2 == 0;
      
      % Two perfect squares are ABCDE and FGHIJK
      var 10000..99999: ABCDE = 10000*A + 1000*B + 100*C + 10*D + E;
      
      var 100000..999999: FGHIJK = 100000*F + 10000*G
      + 1000*H + 100*I + 10*J + K;
      
      predicate is_sq(var int: y) =
        let {
           var 1..ceil(sqrt(int2float(ub(y)))): z
        } in z*z = y;
         
      % Split the six lottery numbers into two perfect squares
      constraint is_sq(ABCDE) /\ is_sq(FGHIJK);
      
      solve satisfy;
      
      output [ "Six Lottery numbers were " ++ show(A) ++ 
      ", " ++ show(BC) ++ ", " ++ show(DE)
      ++ ", " ++ show(FG) ++ ", " ++ show(HI) ++ 
      " and " ++ show(JK) ];
      
      % Six Lottery numbers were 2, 13, 16, 21, 34 and 44
      % % time elapsed: 0.03 s
      % ----------
      % ==========
      
      
      

      Like

      • John Crabtree 4:39 pm on 18 December 2019 Permalink | Reply

        The second square must end in 44 (sq. root = 362 + 50x or 338 + 50x), 36 (sq. root = 344 + 50x or 356 + 50x), or 24 (sq. root = 332 + 50x or 318 + 50x). By use of a calculator, the second square = 213444
        Then the first square must end in 16 (sq. root = 104 + 50x or 146 + 50x). Again by use of a calculator, the first square = 21316.
        And so the six numbers are 2, 13, 16, 21, 34 and 44.

        Like

  • Jim Randell 8:11 am on 24 November 2019 Permalink | Reply
    Tags: by: Alan Hunt   

    Brainteaser 1766: House squares 

    From The Sunday Times, 21st July 1996 [link]

    There is an even number of houses in my road, numbered consecutively from 1 upwards, with the odd numbers on one side and the even numbers on the other.

    My neighbour’s son was practising with his new calculator. He found the sum of the squares of all the house numbers on one side of the road and subtracted it from the sum of the squares of all the house numbers on the other side of the road. The digits in his answer were all the same.

    Noticing that two of the houses displayed “For Sale” signs he decided to carry out a second calculation omitting those two houses. This gave an answer 50% higher than the first.

    Which two houses are for sale?

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

    [teaser1766]

     
    • Jim Randell 8:12 am on 24 November 2019 Permalink | Reply

      This Python program runs in 70ms.

      Run: [ @repl.it ]

      from enigma import seq_all_same, nsplit, irange, div, subsets, printf
      
      # generate the difference between the sum of the even and odd squares up to n
      def generate():
        # sums of squares
        n = d = 0
        while True:
          n += 1
          d -= n * n
          n += 1
          d += n * n
          yield (n, d)
      
      # find solutions to the puzzle
      def solve():
        # look at differences for increasing even n
        for (n, d) in generate():
          # the difference should be a repdigit
          if not seq_all_same(nsplit(d)): continue
          # the second answer is 50% higher
          diff = div(d, 2)
          if diff is None: continue
      
          # look for the house numbers for sale p, q
          for (p, q) in subsets(irange(1, n), size=2):
            delta = sum([-1, 1][x % 2] * x * x for x in (p, q))
            if abs(delta) == diff:
              yield (p, q, n, d, d + diff)
      
      # we only need the first solution
      for (p, q, n, d, d2) in solve():
        printf("for sale = {s} [{n} houses; difference = {d} -> {d2}]", s=(p, q))
        break
      

      Solution: The two houses for sale are 14 and 23.

      There are 36 houses in the street.

      The result of the first calculation is 666.

      The result of the second calculation is 999.

      The difference between the sums of the squares of the first n even numbers and the first n odd numbers can be expressed:

      D(n) = n (2n + 1)

      Which allows a slightly shorter program than generating the differences constructively.

      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: