What is the largest whole number that you can form, such that no pair of consecutive digits occurs more than once? For example you can have 34543, but you cannot have 34534 as the pair "34" occurs twice.


I believe this is the largest number that meets that criteria:



The number has all 100 possible number pairs, from 00 to 99. Furthermore, the number starts with 99, the largest pair, and ends with 09, one of the smallest. Note: I used the zeros in bold to break up the string of numbers so that you can see the method I used to get to my solution.

Because 9989 is the largest possible 4 digit start, and then 7 is the largest number that can come next, I used this strategy to get the rest of the number. 99 to 89 to 79 etc.

  • 3
    $\begingroup$ I was about to post the same answer. Can you elaborate a little on how you constructed it? $\endgroup$ Jun 15 '21 at 13:12
  • 1
    $\begingroup$ Ok. I will continue to edit it. Just wanted to post my answer before anyone else :) $\endgroup$
    – Joe Kerr
    Jun 15 '21 at 13:13
  • 2
    $\begingroup$ @DmitryKamenetsky But what would follow that? Al the 9x pairs have already been used. The only pair with a 9 left is 09 which must go at the end. $\endgroup$ Jun 15 '21 at 13:15
  • 2
    $\begingroup$ If Jaap had a nearly-completed answer that gave that number and explained why, and then Joe posted an answer that just gave the number, I think Jaap should have finished writing up his answer and posted it, and Dmitry should have given Jaap the checkmark if Jaap got a complete answer posted before Joe did. $\endgroup$
    – Gareth McCaughan
    Jun 15 '21 at 16:05
  • 2
    $\begingroup$ I don't mean to imply that there's anything very bad about Joe's answer, of course! And for all I know his complete answer with explanation may still have been faster than Jaap's. I just wanted to put in a word for not necessarily treating a faster-but-less-complete answer as sufficient reason to leave the field to one's rival :-). $\endgroup$
    – Gareth McCaughan
    Jun 16 '21 at 22:50

What is the correct answer depends on the number system that is used.

In Hexadecimal, a common thing to display data from computers, the highest number is (with a space separating each block)

FFEFDFCFBFAF9F8F7F6F5F4F3F2F1F0 EEDECEBEAE9E8E7E6E5E4E3E2E1E0 DDCDBDAD9D8D7D6D5D4D3D2D1D0 CCBCAC9C8C7C6C5C4C3C2C1C0 BBAB9B8B7B6B5B4B3B2B1B0 AA9A8A7A6A5A4A3A2A1A0 9989796959493929190 88786858483828180 776757473727170 6656463626160 55453525150 443424140 3323130 22120 110 0F

In Decimal, as you usually use it in normal math, it is

9989796959493929190 88786858483828180 776757473727170 6656463626160 55453525150 443424140 3323130 22120 110 09

Nonal however is a little shorter, as is Octal (like it was used in some game cartridges):

88786858483828180 776757473727170 6656463626160 55453525150 443424140 3323130 22120 110 08

776757473727170 6656463626160 55453525150 443424140 3323130 22120 110 07

The order of numbers is simply evaluated by a recipe:

For any number system that has more than a single numeral (e.g. 0) each block is set up the same way: H is the absolute highest number that is possible. The highest not-yet used number is M with M<=H and each subsequent M being the former M-1.
Each block with M>0 is made by stacking doublets of (M-N)M, where N is 0 to (M-1)
When N=(M-1) is reached, the block terminates and is ended with a 0 (but no further M) so that each block looks like MM(M-1)M...1M0
As a result, M=2 always is 22120 and M=1 is 110

The last, M=0 termination block, needs to be 0H.

In Binary, the largest possible number indeed does adhere to the exact same recipe, it's simply enough...

the M=1 and termination blocks

110 01

Edge cases:

Note that this system fails to produce meaningful output for position-dependent di-character combinations such as roman numerals: ML (1050) is a valid roman number as is CML (950), but LM is not a valid roman number.

Number systems that include potencies of 10 as special characters can create wildly larger numbers: For example Japanese numerals have special characters for 100, 1000, 10000, 100-million (10^8), 10^12 and 10^16. However, the special rules for them don't allow some of them (the latter 3) to appear more than once and then need to be placed in a non- leading position for maximum effect.

  • 2
    $\begingroup$ This would be an interesting Code Golf challenge, I wonder if it exists yet... $\endgroup$ Jun 16 '21 at 16:34
  • 1
    $\begingroup$ @Trish Now we have both! $\endgroup$
    – AviFS
    Jun 16 '21 at 16:45
  • 1
    $\begingroup$ Well done. I specifically left out "decimal number" from the question to allow answers in other number systems. I am glad you found it. $\endgroup$ Jun 17 '21 at 3:12
  • 2
    $\begingroup$ @DarrelHoffman someone made a Code Golf out of this: codegolf.stackexchange.com/questions/229849/… $\endgroup$ Jun 17 '21 at 3:14
  • 1
    $\begingroup$ @DmitryKamenetsky Yeah, I'm aware, I was helping them out with it in the chat a bit. Thanks though. $\endgroup$ Jun 17 '21 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.