Skip to content

Sunday Times Teaser 3067 – Reciprocal Arrangement

by Brian Gladman on July 2, 2021

by Colin Vout

Published Sunday July 04 2021 (link)

Twelve men from our football squad had turned up for training, and I’d promised them a game of six-a-side at the end of the session; so while they were off on a gentle three-mile run I worked out what the two teams would be. They were wearing their squad numbers, which had one or two digits: 2, 3, 4, 5, 6, 7, 8, 9, 15, and three others. It appealed to me when I found that I could divide them into two teams of six, such that the sum of the reciprocals of the squad numbers in each team equalled one exactly.

What were the squad numbers in the team containing number 2?

From → Uncategorized

8 Comments Leave one →
  1. Brian Gladman permalink

    I am much more interested in code elegance rather than speed but this is quite fast and runs in 1 millisecond on my PC using CPython.

    • Frits permalink

      @Brian, why may “f” not be part of “given” (line 14)?

  2. Brian Gladman permalink

    Because if I allow ‘f’ to be in ‘given’ I would need to adopt a more complex approach. I was aware of this issue but decided not to add the extra complexity since it turned out not to be needed.

    EDIT: The added complexity doesn’t cost as much as I thought it might so I have changed it to avoid this issue.

  3. Erling Torkildsen permalink

    My simplistic programme is supported by a couple of lines arithmetic..

    • Frits permalink

      Nice and short.

      I think the logic to find five numbers should be done immediately when D is updated (and D reset afterwards).

  4. Erling Torkildsen permalink

    Thanks; Frits.
    .
    What I regret the most, is the division in line 11. An extra line comparing the corresponding products, would have eliminated the use of float in the programme all together.

    • Brian Gladman permalink

      Hi Erling, It might be worth looking at the ‘fraction’ module in Python as it can easily solve the issue raised by Frits and your own regret:

      I hesitate to set ‘homework’ for a retired school master, but if you want to be really brave you could avoid using the fractions module by writing a short subroutine to sum reciprocals and return the numerator and denominator of the result!

      • Erling Torkildsen permalink

        Hi Brian, My slow pace in adopting new features is not due to a conservative attitude towards programming. Your second point however, is spot on: As retired, I claim the privilege to not educate myself unless it poses an interesting challenge, and that is what you offer. (As the teasers in general, do.)
        It won’t be tonight though; in twenty minutes there is England vs. Denmark on Wembley Stadion..

Leave a Reply

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

Subscribe to this comment feed via RSS