Tagged: by: R Brain Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 11:22 am on 4 July 2021 Permalink | Reply
    Tags: by: R Brain   

    Brain-Teaser 38: Digital computer 

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

    My nephew Gregory is keen on calendars — an odd interest for a bank clerk.

    “On my next birthday”, he told me yesterday, “I shall take the day off work to celebrate”.

    “To celebrate what?” I asked.

    “To celebrate the fact that it will be the same day of the week as that on which I was born. Moreover, the sum of the digits in the date (e.g. 26/11/1961 = 27) will equal my age, as would also have been the case if had been born just four weeks later than I was”.

    What was Gregory’s date of birth?

    [teaser38]

     
    • Jim Randell's avatar

      Jim Randell 11:23 am on 4 July 2021 Permalink | Reply

      This Python program runs in 54ms.

      Run: [ @replit ]

      from datetime import date, timedelta
      from enigma import dsum, printf
      
      # digit sum of a date
      ddsum = lambda d: dsum(d.day) + dsum(d.month) + dsum(d.year)
      
      # generate dates in a specific range
      inc1 = timedelta(days=1)
      def drange(a, b, step=inc1):
        while not(a > b):
          yield a
          a += step
      
      # consider date of next birthday (within 1 year of the puzzle date)
      for d in drange(date(1961, 12, 10), date(1962, 12, 9)):
        w = d.weekday()
        # must be a workday
        if w == 6: continue
        
        # calculate digit sum (= age)
        n = ddsum(d)
      
        # and calculate the date n years ago
        b = date(d.year - n, d.month, d.day)
      
        # do days of the week match?
        if b.weekday() == w:
      
          # if the birthday was 28 days later ...
          b_ = b + 28 * inc1
          # the digit sum of the nth birthday is also n
          if ddsum(date(b_.year + n, b_.month, b_.day)) == n:
            printf("{d} ({n}) -> born = {b} (+4w = {b_})")
      

      Solution: Gregory was born on Friday, 2nd February 1940.

      So:

      His next birthday, on Friday, 2nd February 1962, is his 22nd.
      And 2+2+1+9+6+2 = 22.

      If he had been born exactly 4 weeks later, it would have been, Friday, 1st March 1940.
      His next birthday, on Thursday, 1st March 1962, is his 22nd.
      And 1+3+1+9+6+2 = 22.

      There is a second candidate solution:

      Gregory was born on Sunday, 11th February 1940.
      His next birthday, on Sunday, 11th February 1962, is his 22nd.
      And 1+1+2+1+9+6+2 = 22.

      If he had been born exactly 4 weeks later, it would have been, Sunday, 10th March 1940.
      His next birthday, on Saturday, 10th March 1962, is his 22nd.
      And 1+0+3+1+9+6+2 = 22.

      But this is eliminated as his next birthday is on a Sunday, so he wouldn’t have to take the day off work.

      Like

    • Jim Olson's avatar

      Jim Olson 9:41 pm on 6 July 2021 Permalink | Reply

      Four weeks after 2/22/1940 would have been 3/21/1940.

      Like

      • Jim Randell's avatar

        Jim Randell 9:51 pm on 6 July 2021 Permalink | Reply

        But if he was born on 22nd February 1940 his next birthday in 1962 would be his 22nd, but the sum of the digits in the date (22/2/1962) would be 24, so it doesn’t work.

        Like

    • Jim Olson's avatar

      Jim Olson 10:06 pm on 6 July 2021 Permalink | Reply

      I think the wording of this Teaser through me off. I see that the 3/21/1962 digits don’t total 22 and that was my problem. 3/1/1940 is not four weeks after his birth. So I didn’t see how this satisfied the requirements of the teaser.

      Like

      • Jim Randell's avatar

        Jim Randell 10:40 pm on 6 July 2021 Permalink | Reply

        1st March 1940 is exactly 4 weeks after 2nd February 1962 because 1940 was a leap year. So the month number goes up 1 and the day number goes down 1, keeping the sum of the digits the same. (Of course the fact that 1962 is not a leap year means that if he had been born 4 weeks later, his next birthday would not be on the same day of the week as the day he was born. But the sum of the digits in the date would be the same as his age, and that is what is important).

        Like

    • Jim Olson's avatar

      Jim Olson 11:50 pm on 6 July 2021 Permalink | Reply

      Apologies I must of misread the posting of the answer as 2/22/1940.

      Like

  • Unknown's avatar

    Jim Randell 9:11 am on 1 October 2019 Permalink | Reply
    Tags: by: R Brain   

    Brain-Teaser 503: [Exam marks] 

    From The Sunday Times, 31st January 1971 [link]

    When the headmaster came to look up Charley’s marks in the previous term’s exam in Physics and Chemistry, sat by the Science pupils of the 6th (Al, Bill, Charley, Dan, Ed, Frank and George) he found that ink had been spilt on the results sheet and only the following was legible:

    He remembered that the pupils finished in alphabetical order in total marks; that there were no ties in either subject, or overall; and that no pupil occupied the same place in each subject.

    All that he could remember about Charley’s results was that he was placed higher in Chemistry than in Physics.

    What were Charley’s marks in each subject?

    This puzzle was originally published with no title.

    [teaser503]

     
    • Jim Randell's avatar

      Jim Randell 9:13 am on 1 October 2019 Permalink | Reply

      I assumed the exams are marked out of 100, and only whole numbers of marks are awarded.

      I made a MiniZinc model for the puzzle. It finds a single solution in 121ms.

      %#! minizinc --solver chuffed --all
      
      include "globals.mzn";
      
      % label the boys
      set of int: Boys = 1..7;
      int: A = 1;
      int: B = 2;
      int: C = 3;
      int: D = 4;
      int: E = 5;
      int: F = 6;
      int: G = 7;
      
      % places for each boy in each subject
      array [Boys] of var 1..7: pPh;
      array [Boys] of var 1..7: pCh;
      
      constraint all_different(pPh);
      constraint all_different(pCh);
      
      % marks for each boy in each subject
      array [Boys] of var 0..100: mPh;
      array [Boys] of var 0..100: mCh;
      
      constraint forall (x, y in Boys where x != y) ((pPh[x] < pPh[y]) -> (mPh[x] > mPh[y]));
      constraint forall (x, y in Boys where x != y) ((pCh[x] < pCh[y]) -> (mCh[x] > mCh[y]));
      
      % given values
      constraint pPh[A] = 5;
      constraint pCh[B] = 2;
      constraint pPh[E] = 3;
      constraint pCh[G] = 5;
      constraint mPh[D] = 70;
      constraint mCh[F] = 67;
      constraint mPh[G] = 71;
      
      % total marks is 1023
      constraint sum (x in Boys) (mCh[x] + mPh[x]) = 1023;
      
      % "the pupils finished in alphabetical order by total marks"
      constraint decreasing (x in Boys) (mPh[x] + mCh[x]);
      
      % "there were no ties in either subject, or overall"
      constraint all_different(mPh);
      constraint all_different(mCh);
      constraint all_different (x in Boys) (mPh[x] + mCh[x]);
      
      % "no pupil occupied the same place in both subjects"
      constraint forall (x in Boys) (pPh[x] != pCh[x]);
      
      % "C placed higher in Chemistry than Physics"
      constraint pCh[C] < pPh[C];
      
      solve satisfy;
      

      Solution: Charley got 73% in Physics and 75% in Chemistry.

      Here is the complete table:

      Like

  • Unknown's avatar

    Jim Randell 8:54 am on 2 March 2019 Permalink | Reply
    Tags: by: R Brain   

    Brain-Teaser 458: [Football tournament] 

    From The Sunday Times, 1st March 1970 [link]

    The table gives the results of an all-play-all soccer tournament is South America.

    If I tell you the number of scores of one goal by either side in the 3 games played by Brazil you can deduce the scores of the games between Argentine and Peru and Argentine and Ecuador.

    What are they?

    This puzzle was originally published with no title.

    [teaser458]

     
    • Jim Randell's avatar

      Jim Randell 8:55 am on 2 March 2019 Permalink | Reply

      The enigma.py library includes the [[ Football() ]] class to help in solving puzzles involving football tables, and the [[ filter_unique() ]] function to help in solving puzzles of the form “… if I told you this, then you could work out that…”. We can use both of these to solve this puzzle.

      This Python program runs in 98ms.

      Run: [ @repl.it ]

      from enigma import Football, filter_unique, unpack
      
      # record possible outcomes
      rs = list()
      
      # scoring system
      football = Football(games='wdl')
      
      # the order of the teams in the table
      (B, A, P, E) = (0, 1, 2, 3)
      
      # digits in the table stand for themselves
      d = dict((x, int(x)) for x in "01234789")
      
      # the columns of the table
      (table, gf, ga) = (dict(w="3100", d="0121", l="0112"), "9724", "3847")
      
      # find possible match outcomes
      for (ms, _) in football.substituted_table(table, d=d):
      
        # find possible scorelines using the goals for/against columns
        for ss in football.substituted_table_goals(gf, ga, ms, d=d):
      
          # record outcomes
          rs.append((ms, ss))
      
      # if I told you...
      # the number of scores of 1 goal by either side in the games played by B...
      f = unpack(lambda ms, ss: sum(v.count(1) for (k, v) in ss.items() if B in k))
      
      # you can deduce the scores in the AvP and AvE match
      g = unpack(lambda ms, ss: (ss[(A, P)], ss[(A, E)]))
      
      # find the unique solutions
      (rs, _) = filter_unique(rs, f, g)
      
      # output solutions
      for (ms, ss) in rs:
        football.output_matches(ms, ss, "BAPE")
      

      Solution: A vs P = 1-1. A vs E = 5-3.

      The scores in all matches are uniquely determined. They are:

      B vs A = 4-1
      B vs P = 3-1
      B vs E = 2-1
      A vs P = 1-1
      A vs E = 5-3
      P vs E = 0-0

      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