Skip to content

Sunday Times Teaser 3112 – PIN

by Brian Gladman on May 14, 2022

by Andrew Skidmore

Published Sunday May 15 2022 (link)

Callum has opened a new current account and has been given a telephone PIN that is composed of non-zero digits (fewer than six). He has written down the five possible rearrangements of his PIN. None of these five numbers are prime; they can all be expressed as the product of a certain number of different primes.

The PIN itself is not prime; it can also be expressed as the product of different primes but the number of primes is different in this case. The sum of the digits of his PIN is a square.

What is the PIN?

From → Uncategorized

9 Comments Leave one →
  1. Brian Gladman permalink

  2. John Z. permalink

    • Frits permalink

      You seem not to have coded the requirement “they can all be expressed as the product of a certain number of different primes”.

      pin5 has to contains 6 elements so for me the name “pin5” was a bit confusing.

  3. John Z. permalink

    Its called pin5 because of the 5 rearrangements. I did hesitate between that and pin6.

    The requirement for ‘different primes’ is coded in line 27.

    It did not occur to me at first that ‘a certain number’ meant that all of the rearrangements except the PIN had to have the same number of prime divisors. I realised this after posting my code and then consulting Brian’s. This verification which it turns out out is redundant to finding the solution would require another two lines of code, for example:

    I admit that calling factor() and factors() several times without storing intermediate results is computationally inefficient but compute time is not an issue for this teaser and it does reduce the line count.

  4. Frits permalink

    Starting from the list of possible squares.

    It would be nice if programs using “number_theory” can be run with PyPy as well.

    • Frits permalink

      I updated my PyPy version and it is supporting the new math functions.

    • Brian Gladman permalink

      Welcome back Frits! On number_theory.py and PyPy, there is only one function (rseq) in the library that PyPy can’t deal with but, sadly, I haven’t figured out how to modify it to get it working on both CPython and PyPy.

      EDIT. Ok, I have now fixed it. Basically, prior to Python 3.8, I had to work around a parameter issue in the call to sum(); but the calling sequence issue with sum() was changed in 3.8 so the fix is no longer needed.

      I’ll update it shortly.

  5. John Z. permalink

    Here is a slightly modified version of my code addressing Frits’ concerns. There was storage of an itermediate result in pinsl (renamed pinnp); this has been moved up about 10 lines:

Leave a Reply

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

Subscribe to this comment feed via RSS