Tagged: by: Sir James Joint Toggle Comment Threads | Keyboard Shortcuts

  • Unknown's avatar

    Jim Randell 9:17 am on 2 July 2023 Permalink | Reply
    Tags: by: Sir James Joint   

    Brain-Teaser 438: Electric clock 

    From The Sunday Times, 28th September 1969 [link]

    My watch keeps perfect time and so does my electric wall clock until the battery starts to run down. I check the clock every noon, and when I find that it has lost a minute in 24 hours I know that it will slow down by an additional minute each day until the battery is exhausted.

    At noon on a day towards the end of August, when I was preparing for a fortnight’s holiday, I noticed that the clock was one minute slow but. I forgot to do anything about it. As I hurried off to catch my train, at noon on 1st September, I saw that the clock was exactly 21 minutes slow. I put it right and left it at that.

    Family matters forced me to return earlier than I had expected and on my arrival home I found that the clock was still going. I then noticed that the hands of my watch were exactly overlapping, while the hands of the clock were almost so.

    It took me only a minute to fix a new battery, and I at once put the clock on the correct time. In doing so the hands crossed each other three times.

    On what date did I return from my holiday?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser438]

     
    • Jim Randell's avatar

      Jim Randell 9:18 am on 2 July 2023 Permalink | Reply

      The clock is 21 minutes slow on 1st Sep, and as 21 is the 6th triangular number it must be progressing as follows (minutes slow at noon on the specified date):

      27th Aug: 1 min (+1)
      28th Aug: 3 min (+2)
      29th Aug: 6 min (+3)
      30th Aug: 10 min (+4)
      31st Aug: 15 min (+5)
      1st Sep: 21 min (+6), corrected to 0 min
      2nd Sep: 7 min (+7)
      3rd Sep: 15 min (+8)
      4th Sep: 24 min (+9)
      5th Sep: 34 min (+10)
      6th Sep: 45 min (+11)
      7th Sep: 57 min (+12)
      8th Sep: 70 min (+13)
      9th Sep: 85 min (+14)
      10th Sep: 99 min (+15)
      11th Sep: 115 min (+16)
      12th Sep: 132 min (+17)
      13th Sep: 150 min (+18)
      14th Sep: 169 min (+19), expected return

      A 12 hour clock has overlapping hands at 12:00, and then every 12/11 hours later.

      gap = 12/11 hours = 65m27.27s

      So we can check times that are multiples of this gap (up to 14 days), and look for times when the hands on the wall clock are separated by a small angle, and it would require 3 crossings of the hands to set to clock to the correct time.

      As the clock is set to a time just after the hands have crossed the amount the clock has lost must be greater than 131 minutes. So the earliest possible date of return is 12th Sep. And a return on 14th Sep wouldn’t be an early return, so the answer must be 12th Sep or 13th Sep.

      This Python program starts by constructing a continuous function to give the amount the clock is slow at any particular time, and it does this by using polynomial interpolation of the times given above at noon on the 1st to 14th Sep. (And as we might expect, that function turns out to be a quadratic polynomial).

      It then looks at times when the hands of a correct clock are overlapping, and calculates the angular distance between the hands on the slow clock. If the hand are less than 10° apart, and setting the clock right requires crossing the hands exactly 3 times, then we have found a solution.

      It runs in 66ms. (Internal runtime is 2.4ms).

      Run: [ @replit ]

      from enigma import (Rational, Polynomial, irange, mdivmod, divc, sprintf, printf)
      
      Q = Rational()
      
      # after h hours, loss (in minutes) is t
      h = t = 0
      ps = [(h, t)]
      for i in irange(7, 19):
        h += 24
        t += i
        # remove (<time>, <loss>) (both in hours)
        ps.append((h, Q(t, 60)))
      
      # p: hour -> hours lost
      p = Polynomial.interpolate(ps)
      printf("[p(x) = {p}]")
      
      # calculate hand positions from time in hours (between 0 and 1)
      def pos(t):
        (z, h, m) = mdivmod(t, 12, 1)
        return (Q(h + m, 12), m)
      
      # angular distance between hand positions (between 0 and 1)
      def ang(t):
        (h, m) = pos(t)
        d = abs(h - m)
        return min(d, 1.0 - d)
      
      # format a time (in hours)
      def fmt(t):
        (d, h, m) = mdivmod(t, 24, 1)
        return sprintf("{d:d}+{h:02d}:{m:05.2f}", m=float(m * 60))
      
      # gap between times of successive overlapping hands
      g = Q(12, 11)
      
      # continue forward from noon on 1st Sep in 12/11 hour increments
      for i in irange(1, 11 * 28):
        # actual elapsed time (hours)
        h = i * g
        # time lost (hours)
        x = p(h)
        # calculate the number of crossings in setting the clock to the correct time
        k = divc(x, g)
        if k != 3: continue
        # clock elapsed time (hours)
        t = h - x
        # calculate the angular distance between the hands
        d = ang(t)
        # look for distances less than 10 degrees
        if not (0 < 360 * d < 10): continue
        # output solution
        printf("[i={i}] {h} -> {t}; {d:.2f} deg; {k} crossings", h=fmt(h), t=fmt(t), d=float(360 * d))
      

      Solution: You returned home on 12th September.

      The polynomial that gives the time lost (in hours) from the time of departure (noon on 1st Sep) is:

      p(x) = (1/69120)x^2 + (13/2880)x

      If the setter returned home at noon on 12th Sep, then the clock would be 132 minutes slow, so it would be showing 9:48am. And the hands are 6° apart, and the minute hand is slightly behind the hour hand.

      The battery is replaced and the clock is set to 12:01pm, which involves the hands crossing at: just before 10, just before 11, 12. So the hands cross 3 times.

      And this is the solution given in the book.

      However the program finds a “better” solution.

      If the setter were to return at 10:54am on 12th Sep (i.e. the previous time the hands on the watch coincide), then the clock would be displaying 8:43am, and the hands are just 1.6° apart, with the minute hand slightly behind the hour hand.

      The battery is replaced and the clock set to 10:55am. So the hands cross at: just before 9, just before 10, just before 11. So the hands cross 3 times, and they started out much closer together than the given solution.

      I also think that the wording of the puzzle implies that setter returned home at an overlapping time other than noon.

      However it doesn’t change the date that the setter returned, so the answer is the same in both cases.

      Like

  • Unknown's avatar

    Jim Randell 3:36 pm on 19 February 2023 Permalink | Reply
    Tags: by: Sir James Joint   

    Brain-Teaser 402: Book pages 

    From The Sunday Times, 19th January 1969 [link]

    A famous book by Brian Teezer has eight chapters, each starting on a right-hand page. All the chapters except one have a half-page of footnotes, which are printed separately after each chapter.

    Each chapter has one more page than the preceding chapter, the last chapter having fewer than 30 pages.

    The current edition of the book contains 200 pages, but the printer has pointed out that when a reprint is issued he can save four pages by assembling the footnotes at the end of chapter 8.

    How many completely blank pages are there in the current edition, and how many will there be in the reprint?

    This puzzle is included in the book Sunday Times Brain Teasers (1974), and is also reproduced on the back cover of the paperback copy of the book I have.

    [teaser402]

     
    • Jim Randell's avatar

      Jim Randell 3:43 pm on 19 February 2023 Permalink | Reply

      This Python program considers the possible numbers of pages for each chapter, and which chapter has no footnotes, until it finds an arrangement that requires 200 pages for the book. It then checks if collecting the footnotes together will save 4 pages.

      It runs in 59ms. (Internal runtime is 817µs).

      Run: [ @replit ]

      from enigma import (irange, tuples, printf)
      
      # allocate pages for the current edition
      def allocate(ps, fs):
        # count blank pages
        b = 0
        # start on page 1
        t = 1
        for (i, p) in enumerate(ps, start=1):
          # allocate the pages for the chapter
          t += p
          # and the footnotes (if necessary)
          t += fs.get(i, 0)
          # insert a blank page (if necessary)
          if t % 2 == 0:
            b += 1
            t += 1
        # return (<total number of pages>, <blank pages inserted>)
        return (t - 1, b)
      
      # consider the number of pages in each chapter
      for ps in tuples(irange(1, 29), 8):
        # consider the chapter with no footnotes
        for nf in irange(1, 8):
          fs = dict((i, 1) for i in irange(1, 8) if i != nf)
          (t, b) = allocate(ps, fs)
          # current edition has 200 pages
          if t == 200:
            # move the 3.5 pages of footnotes to the end of chapter 8
            (t_, b_) = allocate(ps, { 8: 4 })
            # this should save 4 pages
            if t_ + 4 == t:
              # output solution
              printf("chapters = {ps}; nf={nf}")
              printf("  -> cur: pages = {t} total, {b} blank")
              printf("  -> new: pages = {t_} total, {b_} blank")
              printf()
      

      Solution: There are 5 completely blank pages in the current edition. In the reprint there will be 4.

      Chapter 1 has 20 pages, and each subsequent chapter has 1 more page, up to chapter 8 with 27 pages.

      The chapter with no footnotes can be any one of chapters 2, 4, 6, 8, to give a current edition with 200 pages.

      Collecting the 3.5 pages of footnotes together at the end of chapter 8 brings the total number of pages down to 196.

      Like

  • Unknown's avatar

    Jim Randell 10:47 am on 3 May 2020 Permalink | Reply
    Tags: by: Sir James Joint   

    Brain-Teaser 519: Badberg clock 

    From The Sunday Times, 23rd May 1971 [link]

    At the village of Badberg, hidden away in the Alps, there is a town clock of a certain antiquity. The maker was a wealthy but inexpert amateur. After the ornate instrument had been installed it was found that the great hands stood still during the equal intervals between each stroke of the hour on the massive bell. Naturally, the clock was always slow.

    The placid villagers became accustomed to the erratic behaviour of their timepiece; only after the death of its donor did his nephew dare to tackle the problem. Finding it impossible to alter the striking mechanism, he ingeniously modified the movement to run at a higher constant speed so that the hands showed the correct time at least when the clock struck certain hours.

    Unfortunately, the hands still stop for the same period between successive strokes of the bell, but the villages can now see and hear the correct time every six hours.

    At what hours does the clock make its first stroke correctly?

    This puzzle is included in the book Sunday Times Brain Teasers (1974).

    [teaser519]

     
    • Jim Randell's avatar

      Jim Randell 10:47 am on 3 May 2020 Permalink | Reply

      The clock only pauses between the strokes, so at 1 o’clock it doesn’t pause. At 2 o’clock it pauses for 1 interval. At 3 o’clock, 2 intervals. And so on until 12 o’clock when it pauses for 11 intervals. So the total time lost in a 12 hour period is 66 intervals.

      And the speed of the clock is adjusted so that the time lost in these 66 intervals is made up during the 12 hours. So we need to find adjacent 6 hour periods each containing 33 intervals. And there are only 6 pairs of periods to consider.

      Run: [ @repl.it ]

      from enigma import irange, tuples, printf
      
      # "clock" arithmetic
      clock = lambda n, m=12: (n % m) or m
      
      # interval count for each hour
      ps = list(irange(0, 11))
      
      # find a consecutive sequence of 6 intervals that is half the total
      t = sum(ps)
      for (i, s) in enumerate(tuples(ps, 6)):
        if sum(s) * 2 == t:
          (h1, h2) = (i + 1, i + 7)
          printf("{h1}, {h2}", h1=clock(h1), h2=clock(h2))
      

      Solution: The clock is correct at 4 o’clock and 10 o’clock.

      In striking 4, 5, 6, 7, 8, 9 o’clock the clock pauses for 3 + 4 + 5 + 6 + 7 + 8 = 33 intervals.

      In striking 10, 11, 12, 1, 2, 3 o’clock the clock pauses for 9 + 10 + 11 + 0 + 1 + 2 = 33 intervals.

      Like

  • Unknown's avatar

    Jim Randell 8:32 am on 16 February 2020 Permalink | Reply
    Tags: by: Sir James Joint   

    Brain-Teaser 513: [Famiy tree] 

    From The Sunday Times, 11th April 1971 [link]

    Damon Rigby is my grandfather, and his four children (including Henry) are all married. Aunt Fanny is the youngest and at her wedding to Charlie Jones last week I met four of my cousins; only two of our number have the same surnames and only one is married.

    My mother’s name is Mary Rigby and I am her only child. My first name is that of the husband of my oldest aunt, but it is a tradition in our family that blood relations do not carry the same first name.

    Aunt Fanny has a niece whose surname is Finch. Amanda has the same surname as Agatha’s sister. Aunt Doris has but a single daughter. Jack Prior has an aunt married to Tom whose niece is Amy Brown. The first name of Margaret’s father is the same as my father’s.

    What are the full names of the five cousins?

    This puzzle was originally published with no title.

    [teaser513]

     
    • Jim Randell's avatar

      Jim Randell 8:33 am on 16 February 2020 Permalink | Reply

      I assumed a simple scenario with male/female marriages, and no couple having children from outside their marriages.

      I wasn’t really sure on the best way to program a solution, so I started looking at bits I could simplify, and ended up with a complete manual solution. As follows:

      There are four uncle/aunt pairs. And there are five cousins in total – the setter, plus the four cousins he met.

      Assuming that Fanny and Charles don’t have any children. The setter is an only (male) child (of one of the other three uncle/aunt pairs). Another of the pairs has a single female child (Aunt Doris + husband). Which leaves the one remaining aunt/uncle pair with three offspring. Only one of the cousins is married, and only two share the same surname. So of these three one of them must be be a female, who married and changed her name. Leaving the other two unmarried and sharing the same family surname.

      So this gives us the basic structure of the family tree:

      [0] Grandparents; 4 children.

      [1] Henry + Mary; 1 child [setter, male, unmarried]

      [2] Doris + (husband); 1 child [female, unmarried]

      [3] (wife) + (husband); 3 children [1 female, married; 2 unmarried]

      [4] Fanny + Charles; no children.

      Of the aunts/uncles generation there will be a (Henry) Rigby family, and a (Charlie) Jones family, and the remaining two families are from (Finch, Prior, Brown) with the unused one being the name of the married cousin.

      The other two offspring of Damon (other than Henry and Fanny) must also be female (Doris and (not-Doris)) and have changed their names on marriage.

      The setter must be the son of Henry Rigby and Mary (unknown), so he is (unknown) Rigby, sharing a name with the husband of Doris or (not-Doris).

      So, with unknown values in brackets, we have the following 4 families:

      [1] Henry Rigby + Mary (unknown) → (unknown) Rigby [setter, male, unmarried]

      [2] Doris Rigby + (unknown) (Finch/Prior/Brown) → (unknown) (F/P/B) [female, unmarried]

      [3] (not-Doris) Rigby + (unknown) (F/P/B) → (unknown) (was F/P/B) [female, married]; (unknown) (F/P/B) [unmarried]; (unknown) (F/P/B) [unmarried]

      [4] Fanny Rigby + Charlie Jones

      Jack Prior must be one of the unmarried cousins in family [3], so the family name is Prior. He has an aunt married to Tom, this must be family [2], Doris Rigby (married to Tom (Finch or Brown)). Tom has a niece Amy Brown, so Amy Brown must be the married child in family [3], and parents of family [2] are Doris Rigby + Tom Finch.

      [1] Henry Rigby + Mary (unknown) → (unknown) Rigby [setter, male, unmarried]

      [2] Doris Rigby + Tom Finch → (unknown) Finch [female, unmarried]

      [3] (not-Doris) Rigby + (unknown) Prior → Amy Brown (was Prior) [married]; Jack Prior [unmarried]; (unknown) Prior [unmarried]

      [4] Fanny Rigby + Charlie Jones

      Now, “the first name of Margaret’s father is the same as my father” (i.e. Henry). So Margaret can’t be the child in family [2] (as her father’s name is Tom), so she must be in family [3], and the father is Henry Prior.

      [1] Henry Rigby + Mary (unknown) → (unknown) Rigby [setter, male, unmarried]

      [2] Doris Rigby + Tom Finch → (unknown) Finch [female, unmarried]

      [3] (not-Doris) Rigby + Henry Prior → Amy Brown (was Prior) [married]; Jack Prior [unmarried]; Margaret Prior [unmarried]

      [4] Fanny Rigby + Charlie Jones

      The setter’s first name is the same as the husband of his eldest aunt, i.e. Tom Finch or Henry Prior, but the setter can’t be called Henry, as that is his father’s name, so the setter must be Tom Rigby.

      Finally, “Amanda has the same surname as Agatha’s sister”. The child from family [2] does not have a sister, so Agatha must be the mother of family [3], and Agatha’s sister is Doris Finch, so Amanda Finch is her daughter.

      Giving us the complete family tree of:

      [0] Damon Rigby + (unknown) (unknown) → [1]; [2]; [3]; [4]

      [1] Henry Rigby + Mary (unknown) → Tom Rigby [setter, unmarried]

      [2] Doris Rigby + Tom Finch → Amanda Finch [unmarried]

      [3] Agatha Rigby + Henry Prior → Amy Brown (was Prior) [married]; Jack Prior [unmarried]; Margaret Prior [unmarried]

      [4] Fanny Rigby + Charlie Jones

      We don’t know the first name or the maiden name of the grandmother (Mrs Rigby), or the maiden name of Mary Rigby (the setter’s mother), or the first name of Amy’s husband (Mr Brown).

      Solution: The five cousins are: Tom Rigby (the setter); Amanda Finch; Amy Brown, Jack Prior, Margaret Prior.

      Like

  • Unknown's avatar

    Jim Randell 10:54 am on 27 September 2019 Permalink | Reply
    Tags: by: Sir James Joint,   

    Brain-Teaser 502: [Duplicated leaves] 

    From The Sunday Times, 17th January 1971 [link]

    A publisher friend of mine told me the following improbable story. He dreamt that on his shelves he had a collection of twelve books of the same edition of the same title. The curious thing about these books was this:

    The book, as published, ran to 300 pages, but eleven of the books on his shelves had each been bound with duplicate leaves inserted. The number of leaves thus duplicated was different in each volume, all except two being even numbers. They went in ascending order from the book on the left (Volume I), the highest being twenty extra leaves in Volume XI.

    The end book on the right (Volume XII) had 200 pages missing. By a strange coincidence, the duplicated sections from the other volumes exactly filled these gaps. In the reconstituted Volume XII the middle pages (143 to 158) came from the middle volume of the faulty books, while half the duplicated pages came before these and an equal number in the latter half of the volume.

    How many pages were duplicated in Volume IV?

    This puzzle was originally published with no title.

    [teaser502]

     
    • Jim Randell's avatar

      Jim Randell 10:55 am on 27 September 2019 Permalink | Reply

      Assuming that 1 “leaf” consists of 2 “pages” (the “front” (odd numbered) page and “back” (even numbered) page).

      We know vol XII has 200 missing pages (= 100 missing leaves), and each is accounted for (exactly) by the duplicate leaves in vols I – XI.

      Of the 100 duplicate leaves vol XI has 20 of them, so the remaining volumes have 80 duplicate leaves between them.

      This Python program examines this scenario. It runs in 104ms.

      from enigma import (irange, printf)
      
      # decompose total t into k different ascending numbers, min value m
      def decompose(t, k, m=1, s=[]):
        if k == 1:
          if not (t < m):
            yield s + [t]
        else:
          for x in irange(m, t - (k - 1) * m):
            yield from decompose(t - x, k - 1, x + 1, s + [x])
      
      # there are 80 extra leaves amongst vols I - X
      for vs in decompose(80, 10, 1):
        # vol VI has (at least) 8 extra leaves
        if vs[5] < 8: continue
        # and vol XI has exactly 20 extra leaves
        if vs[-1] > 19: continue
        vs.append(20)
      
        # exactly 2 are odd
        if not (sum(x % 2 == 1 for x in vs) == 2): continue
      
        # output the number of duplicate leaves for each volume
        printf("{vs}")
      

      This seems to give 4 possibilities for the numbers of duplicate leaves:

      [1, 2, 3, 4, 6, 8, 10, 12, 16, 18, 20]
      [1, 2, 4, 5, 6, 8, 10, 12, 14, 18, 20]
      [1, 2, 4, 6, 7, 8, 10, 12, 14, 16, 20]
      [2, 3, 4, 5, 6, 8, 10, 12, 14, 16, 20]

      If we’d been asked for the number of duplicate leaves (or pages) in vols VII or VIII there would be a unique solution (10 leaves for vol VII; 12 leaves for vol VIII), but not for vol IV (we have options for 4, 5, 6 duplicate leaves).

      So we need to try an untangle the condition:

      “In the reconstituted Volume XII the middle pages (143 to 158) came from the middle volume of the faulty books, while half the duplicated pages came before these and an equal number in the latter half of the volume.”

      So vol VI must have (at least) 8 duplicate leaves. Which it does in each of our possibilities, so that doesn’t help us.

      The rest of it either doesn’t make sense, or doesn’t seem to be useful.

      “half the duplicate pages” is 50 leaves, so 50 of the duplicate leaves end up making up some of pages 1-142 of vol XII.

      It then goes on to say “and an equal number” (presumably another 50 leaves) “in the latter half of the volume” (presumably pages 151-300), which seems to account for 104 of the 100 missing leaves. So that can’t be right.

      Perhaps it meant “…half the remaining duplicated pages…”, but that just tells us that 46 of the duplicate leaves are used for pages 1-142, and the other 46 are used for pages 159-300, which as we have 92 duplicate leaves to distribute doesn’t seem to help either.

      Another possibility is to ignore the final condition, and take a strict reading of “eleven of the books on his shelves had each been bound with duplicate leaves inserted”, to mean that each book has at least 2 duplicate leaves. This removes the first 3 of the possibilities, leaving:

      I→2, II→3, III→4, IV→5, V→6, VI→8, VII→10, VIII→12, IX→14, X→16, XI→20

      As the only remaining solution, so vol IV has 5 duplicate leaves, and hence 10 duplicate pages. (Which is the published solution).

      We can modify line 13 of the program to [[ decompose(80, 10, 2) ]] to get this single solution.

      Like

  • Unknown's avatar

    Jim Randell 7:04 am on 19 March 2019 Permalink | Reply
    Tags: by: Sir James Joint,   

    Brain-Teaser 465: [Lifts] 

    From The Sunday Times, 26th April 1970 [link]

    Near my house is an impressive block of flats. It stands 16 storeys high, and each story is a lofty 15 feet from floor to floor. My old friends Bob and Horace operate the two lifts, and both start their shift each morning leaving the ground floor at 8 a.m. precisely.

    The two lifts make automatic compulsory stops at the ground level (there is no basement), the 12th and top floors. But below the 12th, Bob serves only the odd-numbered floors, and Horace the even numbers; these stops are also compulsory (up and down). All stops take just 10 seconds, except at ground level where both lifts wait for 20 seconds.

    Above the 12th both Bob and Horace stop as desired, going up and coming down. Both lifts travel between floors at identical speeds.

    Every morning the two attendants make a rendezvous to exchange newspapers and collect their coffee when their arrivals at a certain floor coincide exactly at two minutes after 11 a.m.

    In feet per second what the speed of each lift between stops?

    Note: In the UK the floors in buildings are: ground floor, first floor, second floor, etc.

    Also, as stated this puzzle does not appear to have a unique solution.

    An answer was published (with Teaser 467) stating:

    “This clever trap, with its nice reasoning, outweighed the slight mathematical bias and kept down the entry to a mixed handful.”

    But later, with Teaser 471 the following statement was made:

    “[465: Regretfully a wrong transposition led to a false calculation of time.]”

    In the comments I give a variation on the puzzle that does have a unique answer.

    This puzzle was originally published with no title.

    [teaser465]

     
    • Jim Randell's avatar

      Jim Randell 7:05 am on 19 March 2019 Permalink | Reply

      Replacing the third paragraph (“Above the 12th floor…”) with the following gives a puzzle that does have a unique solution, and it is the same as the published answer.

      The 13th floor is considered to be unlucky, so at the beginning of each day the attendants toss a coin to decide who should service it that day. The loser has to stop at the 13th floor each time they pass it, and the winner stops at the 14th floor each time they pass it. Both lifts take the same amount of time to travel between adjacent floors.

      This Python program can be used to investigate situations where the attendants follow a fixed schedule of stops. And it solves this variation puzzle in 412ms.

      Run: [ @repl.it ]

      from fractions import Fraction as F
      from enigma import printf
      
      # number of seconds between 08:00:00 and 11:02:00
      S = (3 * 60 + 2) * 60
      
      # wait at each floor (seconds)
      wait = [20] + [10] * 15
      
      # generate (<floor>, <seconds>, <n floors>)
      def stops(fs, wait=wait):
        s = n = f = 0
        while True:
          # going up
          for (i, x) in enumerate(fs):
            if i == 0: continue
            s += wait[f]
            n += (x - f)
            f = x
            yield (f, s, n)
          # going down
          for (i, x) in enumerate(reversed(fs)):
            if i == 0: continue
            s += wait[f]
            n += (f - x)
            f = x
            yield (f, s, n)
      
      # collect possible (f, s, n) tuples
      def collect(fs, xs):
        for (f, s, n) in stops(fs):
          if not (s < S): break
          if f in xs: yield (f, s, n)
      
      # solve for specific floors visited by B and H
      def solve(B, H):
        # find common floors
        xs = set(B).intersection(H)
        # collect (<floor>, <seconds>, <n floor>) tuples for each
        Bs = list(collect(B, xs))
        Hs = list(collect(H, xs))
      
        # consider possible meeting stops for B (at time S)
        for (fB, sB, nB) in Bs:
          # calculate time between floors
          t = F(S - sB, nB)
          # look for matching stops for H
          for (fH, sH, nH) in Hs:
            if fH == fB and sH + t * nH == S:
              printf("t={t}s [floor={fB}, B=(wait={sB}s, floors={nB}), H=(wait={sH}s, floors={nH})]")
      
      # send B to floor 13, H to floor 14
      solve(
        [0, 1, 3, 5, 7, 9, 11, 12, 13, 15], # floors for B
        [0, 2, 4, 6, 8, 10, 12, 14, 15], # floors for H
      )
      

      Solution: The time between floors is 3s, giving an average speed of 5 ft/s.

      By 11:02 am, Bob has spent 7410s waiting and travelled 1170 floors. Horace has has waited for 7140s and travelled 1260 floors.

      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