Skip to content

Sunday Times Teaser 2827 – Password

by Graham Smithers

Published: 27 November 2016 (link)

My computer password consists of different digits written in decreasing order.

I can rearrange the digits to form a perfect cube.  A further rearrangement gives a perfect square.  Another rearrangement gives a prime number.  A further rearrangement gives a number that is divisible by the number of digits in the password.  Yet another rearrangement gives a number that is divisible by all but one of its digits.

What is my password?

5 Comments Leave one →
  1. Brian Gladman permalink

  2. Here’s my solution.

    I’ve used some useful routines from the library [ ].

    • I should say that I didn’t write code to ensure that all the 6 mentioned arrangements of digits were different (which I think is implied by the puzzle text), as there was only one possible solution anyway, and looking at the arrangements found by the program it is certainly possible to find 6 different arrangements satisfying the conditions of the problem.

  3. Tony Smith permalink

    Hi Brian
    (1) I think your program would work without the tests for divisibility by 3 and restriction to at most one of 0,3,6,9. If I am right, how would this affect running time?
    (2) Part of the analysis by John Crabtree on your other website shows quickly that the password can only have 4 or 5 digits (he seems to have tested 7 digits despite showing that this would give divisibility by 3).
    Knowing this, your range of cube roots would be much smaller. How would this affect running time?
    (3) Using a bit more of John’s analysis shows that only 13 cube roots need to be tested. Would you be able to write a simpler/quicker program to do this?

    Best wishes
    Tony (non-programming reader and occasional correspondent)

    • Brian Gladman permalink

      Hi Tony,

      (1) As it is now the program completes in 40 milliseconds on my system. If I leave out the two tests you mention, it remains correct (as you say) but it takes over 11 seconds to complete. The answer is still found quickly but the program spends a lot of time considering the larger cubes.

      (2) If I limit the program (as it is now) to five digit cubes, it completes in 20 milliseconds. If I leave out the two tests you mention, this time increases to 35 milliseconds.

      (3) Some of the conditions set in the teaser might not be necessary if only 13 cubes need to be tested so it is possible that the program could be simpler (not as long). But I haven’t looked at what is possible here.

      I didn’t limit the cubes because I only incorporated the logic steps that occurred to me during the initial coding and this wasn’t one of them. And after adding these steps it was fast enough so I didn’t see the need to go any further.

      It is worth noting that the two logic steps I use (with the removal of cubes with duplicated digits) gets the number of cubes down to seven: 4^3, 5^3, 8^3, 13^3, 35^3, 38^3 and 88^3 leading to only six passwords that require further testing (5^3 and 8^3 share the same set of digits as do 35^3 and 38^3).

Leave a Reply

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

Subscribe to this comment feed via RSS