Skip to content

Sunday Times Teaser 3149 – Cube Route

by BRG on January 27, 2023

by Andrew Skidmore

Published Sunday January 29 2023 (link)

I have a set of ten cards, each of which has a different digit written on it. All the cards have been used to make a set of prime numbers. After discarding the smallest prime, and without changing the order of any cards, I have placed the remaining primes in order of decreasing size to give a large number. It is possible, without changing the order of any cards, to break this number into a set composed entirely of cubes. Neither set contains a number with more than four digits.

List, in order of decreasing size, my set of prime numbers.

From → Uncategorized

8 Comments Leave one →
  1. Brian Gladman permalink

    Here is a version that tackles the primes first:

    This runs in about 300ms. But tackling the cubes first is much faster, running in less than 30ms on my PC:

    • John Z. permalink

      I believe a worthwhile speed improvement can be attained by removing the variable ‘n2d’ from the functions ‘compose’, ‘cube_seq’ and ‘prime_seq’ as it is an external variable and is passed unchanged from initial call through all recursions levels. In addition, it is quite a large data structure.

      • John Z. permalink

        remove from the arguments, not completely of course

  2. John Z permalink

    slow but compact

  3. John Z permalink

    Line 30 can be written more efficiently as:

    Walrus notation could also be used to good effect in some places to avoid recalculations.

  4. John Z. permalink

    My take on tackling the cubes first:

    • John Z permalink

      The above runs in 500 microseconds on my system (solution found after 80 microseconds) using:

      etc.

  5. John Z. permalink

    A slighty more compact cubes first version; but is it faster?

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