Skip to content

Sunday Times Teaser 3025 – Please Mind the Gap

by Howard Williams

Published Sunday September 13 2020 (link)

Ann, Beth and Chad start running clockwise around a 400m running track. They run at a constant speed, starting at the same time and from the same point; ignore any extra distance run during overtaking.

Ann is the slowest, running at a whole number speed below 10 m/s, with Beth running exactly 42% faster than Ann, and Chad running the fastest at an exact percentage faster than Ann (but less than twice her speed).

After 4625 seconds, one runner is 85m clockwise around the track from another runner, who is in turn 85m clockwise around the track from the third runner.

They decide to continue running until gaps of 90m separate them, irrespective of which order they are then in.

For how long in total do they run (in seconds)?

14 Comments Leave one →
  1. Brian Gladman permalink

    • Frits permalink

      Hi Brian,

      I think you forgot to use variables, i, j and k.

      Do you need t[2] – 400 in your check function?
      Adding t[0] + 400 seems to be sufficient.

      Will you post an explanation of range(161, 162) ‘after a few days’?
      It is correct though.

      • Brian Gladman permalink

        II posted the wrong version by mistake (a test I was doing to remove the
        somewhat unsatisfactory early exit using exit()). I have updated it but
        I will soon go back to using exit() as Python’s facilities for breaking out
        of nested loops (without adding flags) are not very good.

        On your point about my prefix on ‘t’, it was ‘defensive programming’ since
        I didn’t have a proof that it was unnecessary. EDIT: But the proof is easy
        so either a prefix or a suffix is sufficient.

  2. John Z permalink

    I am not sure if sys.exit() is ok or deprecated. If deprecated, the body of the program can be incorporated in a function and sys.exit() replaced by “return”

    • Brian Gladman permalink

      Hi John,
      Thanks for your posting. I hope you don’t mind but i have made a few small changes to your layout.

      There is no problem with sys.exit() so its fine to use it as you have done. If you exit the loop in this way you can avoid having a loop with an arbitrary end value for range() by using count() instead (see my solution).

  3. John Z permalink

    Brian,
    do you know of an app that reformats Python code according to the style rules? I’d be happy to use it before posting.

  4. Frits permalink

    I like both solutions (I guess “ti” must be set to 4625 together with “import sys”).

    You seem to miss the situation when distances mod 400 are fi 10, 230, 320 at the end.
    In this case they are also 90 meters apart.

    Together with a friend I decided to do a manual solution this time which wasn’t easy. We even used primality. I assume I can publish it next Sunday.

    • Brian Gladman permalink

      Hi John,

      You can check your code with ‘pydocstyle’, or if you want it done automatically, you can use ‘autopep8’ to do it. Both of these are Python applications that can be installed with pip if you know how to use it. If not I can talk you through the installation process via email (or other method) if you need help. I haven’t used either of these tools as I have just learnt the main rules – to be honest there is not much I feel the need to change in your code – in the main it is spaces around operators and spaces after commas, both of which make code easier to read. There is a nice exposition of PEP8 here which is worth a read.

      • Frits permalink

        Hi John,

        In Wing Python IDE which Brian suggested to me there also is a “Reformat PEP8” option.
        So far I like using Wing to test Python code.

    • Brian Gladman permalink

      Hi Frits,

      You can publish the solution on the manual solutions site I manage here where the rule we apply there is ‘after a few days’.

      I do sometimes publish manual solutions here when a teaser is not amenable to a Python solution but its not the norm and I don’t want to encourage this because the primary focus here is on Python rather than puzzles.

      Moreover I want to encourage people to install Python and find the answers rather than just looking for answers here (even downloading and running the code published here is a start!).

      You are right about missing some solutions. I originally had a complete check for gaps but I took it out when I found it made no difference. It was also a bit messy but I will probably put it back if I can find a more elegant version.

    • John Z permalink

      Frits: you are right: import sys and ti = 4625 didn’t get into the copy and paste into this page. My apologies. And your concern about a 90m separation across the 400m mark is valid. But I modified my program to take this into account and 10, 230, 320 don’t come up. I’ve also modified a number of other aspects of the program to make it more compact.

      • Frits permalink

        I like the simple way you solved the gap issue.

        We could already check Ann’s and Beth’s distances on gap difference before looking at Chad but as range(1, 10) is quite limited this is not really an issue.

  5. John Z permalink

    Making a simple mod to the code, I checked what the solutions would like for separations from 95m to 130m in 5m steps. Here they are:

    Time 7250s Speeds: 4.0 5.68 6.44 positions 200 380.0 290.0 separation: 90
    Time 29875s Speeds: 4.0 5.68 6.44 positions 300 90.0 395.0 separation: 95 overlap
    Time 7500s Speeds: 4.0 5.68 6.44 positions 0 200.0 300.0 separation: 100 overlap
    Time 5125s Speeds: 4.0 5.68 6.44 positions 100 310.0 205.0 separation: 105 overlap
    Time 7750s Speeds: 4.0 5.68 6.44 positions 200 20.0 310.0 separation: 110 overlap
    Time 29625s Speeds: 4.0 5.68 6.44 positions 100 270.0 385.0 separation: 115 overlap
    Time 7000s Speeds: 4.0 5.68 6.44 positions 0 160.0 280.0 separation: 120 overlap
    Time 5625s Speeds: 4.0 5.68 6.44 positions 100 350.0 225.0 separation: 125 overlap
    Time 8250s Speeds: 4.0 5.68 6.44 positions 200 60.0 330.0 separation: 130 overlap

    As you can see, everything over the original separation has a separation overlapping the start/finish line.

    Thanks, Frits for suggesting Wing Personal. I downloaded it. Works fine including PEP 8 reformatting. I do prefer the simplicity of the IDLE user interface.

  6. Erling Torkildsen permalink

Leave a comment to Frits Cancel reply

Note: HTML is allowed. Your email address will not be published.

Subscribe to this comment feed via RSS