Skip to content

# Sunday Times Teaser 2625 – Mind the Gap

### by Nick MacKinnon

If all ten digit numbers with no repeated digits are listed in increasing order, the first is 1023456789 and the last is 9876543210.

The difference between consecutive numbers in this list is never equal to the average of all such differences.

What is the value of the difference that is closest to their average?

4 Comments Leave one →
1. Brian Gladman permalink

Here is my solution:

2. Another solution:

• Brian Gladman permalink

HI Arthur

Your method of generating the numbers looked slow to me so I tried out three methods on Python 3 using the following code:

The result I got is:

String: 09.64 seconds
Reduce: 23.88 seconds
Sum: 76.88 seconds

which confirmed my gut feeling. However, these times might be Python 3 specific so it would be interesting to see how Python 2 and PyPy fare on this.

• Arthur Vause permalink

Admittedly not one of my fastest bits of Python. However, the variation in timings is far less with Python 2.7.3:

String: 08.28 seconds
Reduce: 09.09 seconds
Sum: 17.19 seconds