As many people, I have to deal with a lot of numbers all the time (bug numbers, changelist numbers, tracking numbers, ...) and as a mathematician I sometimes notice when numbers have peculiar properties.

For example, I recently ran into 152463, which is a straight (made up of consecutive digits, not necessarily in order.) I then ran into 35426, which is also a straight. Is this odd?

To put it another way - *what proportion of numbers are straights?*

We consider only non-negative integer numbers {0, 1, 2, ... }. No duplicate digits are allowed, so the very last straight is 9,876,543,210.

Break it down by the length of the number in digits. For example, how many four-digit numbers are there? We can choose any number from 1-9 for the first digit, and any number from 0-9 for each of the other three digits; so there are 9 * 10^{3 }numbers of length 4.

How many of these are straights? There are seven ways to choose a set of four consecutive digits to make up a four-digit straight: {0,1, 2, 3}, {1, 2, 3, 4}, {2, 3, 4, 5}, {3, 4, 5, 6}, {4, 5, 6, 7}, {5, 6, 7, 8}, {6, 7, 8, 9}.

Each of these seven ways can then be shuffled to make the straights themselves. For six of these seven sets of digits, all possible shufflings are allowed; there are 4! shufflings for each set. This gives 6 * 4! straights.

But for {0, 1, 2, 3}, we have to be careful not to end up with 0 as a leading digit. We choose the leading digit first out of the set {1, 2, 3} (there are three ways to do this) and then we have complete freedom to shuffle the three remaining digits (including 0.) This gives 3 * 3! straights.

So there are 6 * 4! + 3 * 3! straights which are four digits long.

Considering all possible lengths from 1 to 10 (we'll consider 0 as a number of length 1) gives the following table:

Length |
Numbers |
Straights |
% Straights |

1 | 10 | 10 | 100.000% |

2 | 9 * 10^{1} |
17 | 18.889% |

3 | 9 * 10^{2} |
46 | 5.111% |

4 | 9 * 10^{3} |
162 | 1.800% |

5 | 9 * 10^{4} |
696 | 0.773% |

6 | 9 * 10^{5} |
3480 | 0.387% |

7 | 9 * 10^{6} |
19,440 | 0.216% |

8 | 9 * 10^{7} |
115,920 | 0.129% |

9 | 9 * 10^{8} |
685,440 | 0.076% |

10 | 9 * 10^{9} |
3,265,920 | 0.036% |

Total |
10^{10} |
40,91,131 | 0.041% |

Since roughly 1% of five-digit numbers are straights, it is not surprising that I see them that often.

typo: the very last straight is:9,876,543,210

@bahbar thanks; fixed.