Skip to content

Sunday Times Teaser 3249 – Test to Twelve

by BRG on December 30, 2024

by Victor Bryant

Published Sunday December 29 2024 (link)

I have been testing for divisibility by numbers up to twelve. I wrote down three numbers and then consistently replaced digits by letters (with different letters used for different digits) to give

TEST TO TWELVE

Then I tested each of these numbers to see if they were divisible by any of 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 or 12. It turned out that each of these eleven divisors was a factor of exactly one of the three numbers.

What are the three numbers?

From → Uncategorized

6 Comments Leave one →
  1. BRG permalink

    This is slow but I am short of time at the moment. I might speed it up later.

    A lot faster with some analysis (including suggestions from John below):

    • John Z permalink

      Brian, I think that in line 17 the

      + ‘0’

      is extraneous and results in an inconsequential length mismatch.
      Rewriting line 17 as

      produces a different inconsequential length mismatch with ‘st’ now being longer.
      I suspect that you already noticed this.

      • BRG permalink

        Thanks John,

        I corrected this locally (and made another change) but forgot to upload the change.

    • John Z permalink

      Is there any advantage to using the ‘update’ method in lines 20 and 23 as opposed to making a direct assignment such as:

      Also, neither T nor O can be 5 because 5 would divide both TWELVE and one of TEST or TO. Modifying lines 16 and 19 accordingly will remove most candidate values.

      • BRG permalink

        Hi John,

        Answering your first question, there is no advantage in my code above but more
        generally there can be as it allows more than one change without using multiple
        dictionary assignments or the dict(zip(a, b)) approach. For example, had I needed
        to update O and S together, I could use:

        I feel that this has an advantage in readability terms when a few updates are
        needed.

        Thanks for the further speed up suggestions that I will now look at adopting.

  2. John Z permalink

    Brute force:

Leave a comment to BRG Cancel reply

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

Subscribe to this comment feed via RSS