Inspired by the problem with the same name on Puzzling SE by our very own Dmitry Kamenetsky.
You are to find the largest number that only uses every digit pair once, in a given base. For example, in ternary we have 2212011002.
Challenge: Given a base from 2-10, output the largest number in that base with no repeating digit pairs.
As long as the digits make the number, you may output with anything, or nothing, in between. Whether regularly delimited, or irregularly gibberished.
You may also take input in any reasonable way. For example, you might take the base, the max digit, or an ordered list representing the digits available. For octal, this would mean 8
, 7
or 76543210
. If you feel like a challenge, you can take octal
as input. I won't complain!
Note that it need only work for bases from 2-10. Invisible points for doing alphanumeric bases like hex, but not at all required.
This is code-golf, so least bytes per language wins.
Test Cases
Decimal: 10
99897969594939291908878685848382818077675747372717066564636261605545352515044342414033231302212011009
Octal: 8
77675747372717066564636261605545352515044342414033231302212011007
Quaternary: 4
33231302212011003
Ternary: 3
2212011002
Binary: 2
11001
Edit: It used to be required for bases 1-10, with the desired output for unary being 00
. However, that was just an obfuscating edge case in some cases when people wanted to manipulate natural numbers. So unary has been dropped; only bases 2-10 required.