Skip to content

Sunday Times Teaser 3112 – PIN

by BRG 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

10 Comments Leave one →
  1. Brian Gladman permalink

    • John Z permalink

      If I rewrite your line 30

      as :

      your code works on my PC.
      This is what I get if I type the following directly after starting IDLE:

      Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
      Type “help”, “copyright”, “credits” or “license()” for more information.
      from number_theory import factor, factors
      factor(1771)

      factors(1771)

      There is an implementation difference between your machine and mine. As you can see, I’m running version 3.10.4 which is the latest stable release having upgraded from a 3.9 version. Your thoughts?

  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:

  6. Frits permalink

    Generating 4-digit numbers which are a product of different prime numbers.

Leave a comment to Brian Gladman Cancel reply

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

Subscribe to this comment feed via RSS