[Question]
  [
*Inspired by [the problem with the same name](https://puzzling.stackexchange.com/questions/110490/largest-number-with-no-repeating-digit-pairs) on [Puzzling SE](https://puzzling.stackexchange.com) by our very own [Dmitry Kamenetsky](https://codegolf.stackexchange.com/users/92610/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](/questions/tagged/code-golf "show questions tagged '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.
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-1 thanks to [Neil](https://codegolf.stackexchange.com/users/17602/neil) (avoid a reverse by reordering to flatten first.)
```
Żj)ŻFṚ;
```
A monadic Link accepting the maximal digit (e.g. `7` for octal) that yields the digits as a list of integers.
**[Try it online!](https://tio.run/##y0rNyan8///o7oc7Z2Vpgik36////5sDAA "Jelly – Try It Online")**
### How?
Note that if `x` is the base then the least significant (rightmost) digit of `f(x)` is `x-1`, the previous digits are the same as all but the last digit of `f(x-1)` and the digits before that are:  
`[x-1, x-1, x-2, x-1, x-3, x-1, x-4, x-1, ..., 0]`, so...
```
Żj)ŻFṚ; - Link: non-negative integer, M (max digit = base - 1)
  )     - for each (x in [1..M]):
Ż       -   zero-range    -> [0,1,2,3,...,x]
 j      -   join (x)      -> [0,x,1,x,2,x,3,x,...,x]
   Ż    - prepend a zero  -> [0,[0,1,1],[0,2,1,2,2],[0,3,1,3,2,3,3],...]
    F   - flatten         -> [0,0,1,1,0,2,1,2,2,0,3,1,3,2,3,3,...]
     Ṛ  - reverse         -> [...,3,3,2,3,1,3,0,2,2,1,2,0,1,1,0,0]
      ; - concatenate (M) -> [...,3,3,2,3,1,3,0,2,2,1,2,0,1,1,0,0,M]
```
[Answer]
# [R](https://www.r-project.org/), ~~61~~ ~~52~~ 51 bytes
*Edit: -9 bytes, and then -1 more byte, thanks to Robin Ryder*
```
for(i in 1:scan())F=c(i,rbind(i,i:1-1),F);c(F,F[1])
```
[Try it online!](https://tio.run/##K/r/Py2/SCNTITNPwdCqODkxT0NT0802WSNTpygpMy8FSGdaGeoaauq4aVona7jpuEUbxmr@t@TiKsrVAAkllmgoxeQpaXKRYQyXOXWMMaaOMUbUMcbwPwA "R – Try It Online")
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~14~~ 11 bytes
```
Çò qZÃ¬Ô+´U
Ç           // Exclusive range [0..U) where U is the input, mapped to
 ò          // inclusive range [0..Z] of each item Z
   qZ       // joined together by Z.
     Ã¬Ô    // Join and reverse the result, then
        +´U // append input minus one.
```
[Try it here.](https://ethproductions.github.io/japt/?v=1.4.6&code=x/IgcVrDrNQrtFU=&input=OA==)
[Answer]
# JavaScript (ES6), 55 bytes
```
n=>(g=p=>p--?p+(h=q=>q--?[p]+q+h(q):'')(p)+g(p):~-n)(n)
```
[Try it online!](https://tio.run/##ZcjLCoMwEEbhfV/E@QkptboowqQPUroQL9Eik4mKy7566rZkczh8n/Zot26ddbcS@iGNnIQdeVZ2au1TDU0c2cXzX/o20UwU0RQFSGH8meZrBSRIXZAtLMN1CZ5GKm/A5Z8emdSZVJncMymB9AM "JavaScript (Node.js) – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
,€`€j0ṚF;Ø0;
```
[Try it online!](https://tio.run/##y0rNyan8/1/nUdOaBCDOMni4c5ab9eEZBtb///@3BAA "Jelly – Try It Online")
Takes `base - 1` for input, so `7` for octal. Does not work for unary, as permitted.
```
,€`€j0ṚF;Ø0;  Main Link
   €          For each x from 1 to N
  `           Apply the following to (x, x) rather than (x, N):
 €            - For each y from 1 to x
,             - (y, x)
    j0        Join the list of sublists of pairs on 0
      Ṛ       Reverse the whole thing
       F      Flatten
        ;Ø0   Append 2 zeroes
           ;  Append the input
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
;€`Ṛ)ŻṚj0F;
```
[Try it online!](https://tio.run/##y0rNyan8/9/6UdOahIc7Z2ke3Q0kswzcrIFCDXMUdO0UHjXMtT7cfnTSw50zVLgsj@4@3A5UG/kfAA "Jelly – Try It Online")
A monadic link taking the max digit and returning a list of digits. Works for unary as well.
## Explanation
```
    )       | For each digit from 1 up to the argument:
;€`         | - Concatenate each digit from 1 to that digit together
   Ṛ        | - Reverse
     Ż      | Prepend zero
      Ṛ     | Reverse
       j0   | Join with zeros
         F  | Flatten
          ; | Concatenate to original argument
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~56~~ 53 bytes
```
->n{(?0..n="#{n}").map{|m|[*?0..m]*m}.join.reverse+n}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6vWsPeQE8vz1ZJuTqvVklTLzexoLomtyZaCyScG6uVW6uXlZ@Zp1eUWpZaVJyqnVf7v6C0pFhBw1BPzxKsXEMtTfM/AA "Ruby – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 16 bytes
```
ʁ?²›↔'₌ḢṪZ:U⁼;tṅ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=%CA%81%3F%C2%B2%E2%80%BA%E2%86%94%27%E2%82%8C%E1%B8%A2%E1%B9%AAZ%3AU%E2%81%BC%3Bv%E1%B9%85t&inputs=3&header=&footer=)
Sorry about that. I wayyyy misinterpreted the question.
##### Explanation:
```
ʁ?²›↔'₌ḢṪZ:U⁼;tṅ    # main program
ʁ                   # range 0 to n-1
 ?²›                # base^2 + 1
    ↔               # combination w/ replacement
     '₌ḢṪZ:U⁼;      # filter lambda
      ₌ḢṪ           # a[1:], a[:-1]
         Z          # zip
          :U⁼       # check if the zip is unique
              tṅ    # tail joined by ""          
```
This is really slow, so it will only finish for n <= 3 probably, but it works in theory.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 13 bytes
```
⮌⁺⊖θ⭆Ｎ⪫…·⁰ιＩι
```
[Try it online!](https://tio.run/##HYtBCsJADEWv0mUKFVy4c6kbBaW0J4hjqIFpWjOZuX4MvuV//6UPatowu4/KYjBRIy0EY64FrpSUVhKjN3z7oZstPssDd7jJXu1Z1xcphLhvLLGliLjRhLIQHIeOQ12wGHD/5@x@8kPLPw "Charcoal – Try It Online") Link is to verbose version of code. Takes `b` as input. Works for `b=1`. Explanation:
```
     Ｎ          Input `b`
    ⭆           Map over implicit range and join
       …·⁰ι     Inclusive range from 0 to current index
      ⪫         Joined with
            ι   Current index
           Ｉ    Cast to string
 ⁺              Prefixed with
   θ            Input `b`
  ⊖             Decremented
⮌               Reverse
                Implicitly print
```
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 51 bytes
```
.+
$*
1
$`¶
¶$
1
$.%_
$.%`
^(.*¶)*
$#1$&
¶
O$^`.
```
[Try it online!](https://tio.run/##K0otycxL/M9laKCidWgbF5eKXgKXoWMCl6qGe8J/PW0uFS0uQy6VBKDUoW0qXCC2nmo8SJlqAlechh5Qj6YWl4qyoYoaF0i7v0pcgt7//wA "Retina 0.8.2 – Try It Online") Link includes test suite that generates results for `b=1..10`. Explanation:
```
.+
$*
```
Convert to unary.
```
1
$`¶
```
List the values from `0` to `b-1` (in unary).
```
¶$
```
Delete the trailing newline that the previous stage generates.
```
1
$.%_
```
Replace each `1` with its line number, so now we have a triangle of digits where there are `n` digits `n` on each line.
```
$.%`
```
Intersperse the digits from `0` to `n` around the existing digits `n`.
```
^(.*¶)*
$#1$&
```
Insert an extra digit `b-1` at the beginning.
```
¶
```
Join everything together.
```
O$^`.
```
Reverse the string.
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~15~~ ~~13~~ 11 bytes
*Edit: -2 bytes thanks to Razetime*
```
↔:¹ṁSoJ←ŀḣ→
```
[Try it online!](https://tio.run/##AS8A0P9odXNr/23igoH/4oaUOsK54bmBU29K4oaQxYDhuKPihpL///9bMSwyLDMsNyw5XQ "Husk – Try It Online")
```
↔:¹ṁSoJ←ŀḣ→ # Full program:
   ṁS       # map across
         ḣ→ # each integer n from 1 to input plus 1:
        ŀ   # integers from zero to n,
     oJ←    # joined-together using n plus 1;
 :¹         # then, prefix this with the input,
↔           # and reverse it all.
```
[Answer]
# [Python 3](https://docs.python.org/3/), 52 bytes
```
f=lambda a,*b:(b and a+a+a.join(b)+f(*b)[:-1]or a)+a
```
[Try it online!](https://tio.run/##K6gsycjPM/7/P802JzE3KSVRIVFHK8lKI0khMS9FIVEbCPWy8jPzNJI0tdM0tJI0o610DWPzixQSNbUT/xcUZeaVaADFldxcXZydHC0tzM1MTYyNDA2UNDW5ELK4xLGLYopgCKDzQdz/AA "Python 3 – Try It Online")
* Take as inputs each individual available digits in descending order.
* Bonus: Base 0 works perfectly fine, so does other bases like Hexadecimal (as long you provide the digits available)
## How it works:
Let say your digits are `"43210"`, the expcted result should be `4(4)3(4)2(4)1(4)0__3(3)2(3)1(3)0__2(2)1(2)0__1(1)0__0__[4]`
* We can see that each segent contains the numbers up to a certain point separated by the leading number.
* These segments repeat in decending order
* The first number is added at the end
From that I construct the recursive program :
* `f=lambda a,*b:`: definition of the function, each individual digit in descending order. Store the first in `a` and the other in `b`
* `b and ... or a` if the digits is just `"0"`, `b` is empty and the expression will be equal to `"0"`, else it will be equal to `...`
* `a+a+a.join(x)+f(b)[:-1]`, return the string of the available digits separated by the first element (`a`), then recurse over the available digits the first element. Then remove the last digit of it.
* `return(...)+a` add the first element of `x` to the result. The previous `[::-1]` is to remove this char from the recursive call but not from the main call.
[Answer]
# [Python 3](https://docs.python.org/3/), 97 bytes
```
def f(x):
	k=[]
	for i in range(x,0,-1):k+=sum([[i-j,i]for j in range(i)],[])+[0]
	return k+[0,x]
```
[Try it online!](https://tio.run/##Rc1BCoMwEIXhtZ4iywyOkNCd4EmGWQhN7BgaJY2Qnj6alcsHH@8//vmzx1etb@eV1wWmvgszcd/5PSlRElVa4up0QYOjhSkM8@/8aiIZNxRuanuUACMxDGTuh@TymaIK98LCtdHyUIvWtNqRJGbd0lAv "Python 3 – Try It Online")
fixed thanks to Jakque
Takes `base - 1` for input, so `7` for octal. Does not work for unary, as permitted.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~13~~ 10 bytes
*-3 thanks to [ovs](https://codegolf.stackexchange.com/users/64121/ovs).*
```
ÝεÝy.ý}˜Rš
```
[Try it online!](https://tio.run/##ARsA5P9vc2FiaWX//8OdzrXDnXkuw719y5xSxaH//zk "05AB1E – Try It Online") Takes input as the maximum digit in the base, and outputs as a strangely arranged list of numbers - this is allowed, since
> 
> As long as the digits make the number
> 
> 
> 
it is valid.
```
ÝεÝy.ý}˜Rš  # full program
         š  # prepend...
        R   # reversed...
       ˜    # flattened...
Ý           # [0, 1, 2, ...,
            # ..., implicit input...
Ý           # ]...
 ε          # with each element replaced by...
  Ý         # [0, 1, 2, ...,
            # (implicit) ..., current element in map...
  Ý         # ]...
    .ý      # joined by...
   y        # current element in map...
         š  # to...
            # implicit input
      }     # exit map
            # implicit output
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 15 bytes
```
@ORV:0\,_J_MJ,a
```
[Try it online!](https://tio.run/##K8gs@P/fwT8ozMogRifeK97XSyfx////xgA "Pip – Try It Online")
### Explanation
We construct (most of) the number backwards and then reverse it:
```
                                                      Current value         Output
              a  The base, given via command-line     3
             ,   Range(^)                             [0 1 2]
           MJ    Map this function...
     0\,_          Inclusive-range(0, arg)            [[0] [0 1] [0 1 2]]
         J_        joined on arg                      [0 011 02122]
                 ... and join the results as string   001102122
  RV:            Reverse                              221201100
 O               Output without a newline             221201100             221201100
@                Get the first character              2                     221201100
                 (Autoprint)                                                2212011002
```
[Answer]
# [*Acc!!*](https://github.com/dloscutoff/Esolangs/tree/master/Acc!!), 100 bytes
```
N-48
Count i while _+1-i {
Count j while _-i-j {
Write _-i-j+48
Write _-i+48
}
Write 48
}
Write _+48
```
Takes input as (base - 1). [Try it online!](https://tio.run/##S0xOTkr6/99P18SCyzm/NK9EIVOhPCMzJ1UhXttQN1OhGiqaBRPVzdTNAoqGF2WWQHnaQK1wLohTC@UiMeOB4v//WwIA "Acc!! – Try It Online")
### Explanation
```
N-48                     # Input a digit and store its value in the accumulator
Count i while (_+1)-i {  # Loop i from 0 through (acc + 1) - 1
                         #   acc - i is the recurring digit in this block
Count j while (_-i)-j {  # Loop j from 0 through (acc - i) - 1
                         #   acc - i - j is the changing digit in this block
Write (_-i-j)+48         # Write the changing digit
Write (_-i)+48           # Write the recurring digit
}
Write 48                 # End the block with a 0
}
Write _+48               # End the number with a final digit of (base - 1)
```
]