[Question]
  [
Your task is to take a positive number as input, **n**, and output the length of the longest rep-digit representation of **n** in any base. For example 7 can be represented as any of the following
```
111_2
21_3
13_4
12_5
11_6
10_7
7_8
```
The rep-digits are `111_2` and `11_6`, `111_2` is longer so our answer is 3.
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") question so answers will be scored in bytes, with fewer bytes being better.
# Test Cases
```
1   -> 1
2   -> 1
3   -> 2
4   -> 2
5   -> 2
6   -> 2
7   -> 3
8   -> 2
9   -> 2
10  -> 2
11  -> 2
26 -> 3
63  -> 6
1023-> 10
```
# Sample implementation
Here is an implementation in Haskell that can be used to generate more test cases.
```
f 0 y=[]
f x y=f(div x y)y++[mod x y]
s x=all(==x!!0)x
g x=maximum$map(length.f x)$filter(s.f x)[2..x+1]
```
[Try it online!](https://tio.run/##NYy9CsMgGEX3PIUBB0NATHbfoFtHcRDiH/00IWpr@vI2CXQ758C9TqWXBmjNIIYOLmRnUD3BkMW/LxqOcRRhXS6WXUKVKwDCee17NtTOniGo6kMJOKiNgI42O3qeDNh4yHon6TYxU1rHSbagfORbyc@8PyIuEXzU6dqi5NYP/vpNTJTOjMk72r@1Hw "Haskell – Try It Online")
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~9~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-2 thanks to caird coinheringaahing (`‘Ḋ$` -> `‘€` and use of the newer alias for `Ðf`, `Ƈ`.)
```
b‘€EƇZL
```
A monadic link accepting and returning numbers
**[Try it online!](https://tio.run/##y0rNyan8/z/pUcOMhzu6VFwPT0iL8vn//785AA "Jelly – Try It Online")** or see a [test suite](https://tio.run/##y0rNyan8/z/pUcOMhzu6VFwPT0iL8vkfdLj9UdOa//@NjQA "Jelly – Try It Online") (inputs one to 32 inclusive).
### How?
```
b‘€EƇZL - Link: number, n
  €     - for each (i in [1..n]):
 ‘      -   increment = i+1
        - -> [2,3,4,...,n+1]
b       - convert (n) to those bases
    Ƈ   - filter keep if:
   E    -   all elements are equal
     Z  - transpose
      L - length (note:  length of the transpose of a list of lists is the length of the
        -                longest item in the original list, but shorter than L€Ṁ)
```
---
Or maybe I should have done:
```
b‘€EƇZLo1
```
...just for the `Lo1`z.
[Answer]
## JavaScript (ES6), 62 bytes
```
f=(n,b=2,l=0,d=n)=>d?n%b<1|n%b-d%b?f(n,b+1):f(n,b,l+1,d/b|0):l
```
```
<input oninput=o.textContent=f(this.value)><pre id=o>
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~86~~ ~~81~~ 79 bytes
*2 bytes saved thanks to Laikoni*
```
0!y=[]
x!y=mod x y:div x y!y
length.head.filter(all=<<(==).head).(<$>[2..]).(!)
```
[Try it online!](https://tio.run/##HYuxDsIgFEX3fkVpOkBqXlpH0@cXuDkSBhIQiECbFrV8PaJnOSc3uVbuT@19KSPJyEVzVIVFtUebL8q9fya5Meh1NMmC1VLBw/mkNyq9x3mmiOw/M6Bzf@VnAFGTsBKki7i@0j1tt9jTYehOHauPIFe62@UDhvEJYBoronwB "Haskell – Try It Online")
Since this has died down a bit, here's my approach. It's a golfed version of the sample code I made for the question. I think it can definitely be shorter. I just thought I'd put it out there.
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~13~~ 11 bytes
-2 bytes thanks to zgarb
```
L←fȯ¬tuMBtN
```
[Try it online!](https://tio.run/##yygtzv7/3@dR24S0E@sPrSkp9XUq8fv//7@hAQA "Husk – Try It Online")
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 8 bytes
```
L>вʒË}нg
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fx@7CplOTDnfXXtib/v@/OQA "05AB1E – Try It Online")
-1 thanks to [kalsowerus](https://codegolf.stackexchange.com/users/68910/kalsowerus).
[Answer]
# Mathematica, 71 bytes
```
Max[L/@Select[Array[a~IntegerDigits~#&,a=#,2],(L=Length)@Union@#==1&]]&
```
[Try it online!](https://tio.run/##BcFNC8IgHAfgrxIIsuAH5no/CAZdAoMgOokHGc4JzcD9D0W0r27PM3oaUjfVXtWrf1sj9D08Q0f2VIr/WD9fMoUYyjnFRNPMOLxiaB0ao0zIkYalfuT0ypopJblzvN5KyrQQuhf6K9FijQ222GGPA46QK0j5q38 "Mathics – Try It Online")
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 12 bytes
```
+₁⟦₁b∋;?ḃ₍=l
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/X/tRU@Oj@cuAZNKjjm5r@4c7mh819drm/P9v/j8KAA "Brachylog – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~92~~ 87 bytes
5 bytes thanks to Halvard Hummel.
```
g=lambda n,b,s=1:s*(n<b)or(n%b**2%-~b<1)*g(n//b,b,s+1)
f=lambda n,b=2:g(n,b)or f(n,b+1)
```
[Try it online!](https://tio.run/##TYu9DoIwFEZ3n6ILSVs/g221akOfxDjQmCIJXgiwuPjq9bK5fT/nTJ/1NZIrpYtD@07PVhASlmjCoiU1SY2zpCppbavDNzVG6U5SXacN2hu1y39atIFPbI7IW2CgZC4kehJ3AwuHE87wuOCKG8wRhlcP7zhb9whimntaJdtKlR8 "Python 3 – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 7 bytes
```
LḟEMBtN
```
[Try it online!](https://tio.run/##yygtzv7/3@fhjvmuvk4lfv///zc0MDIGAA "Husk – Try It Online")
### Explanation
```
LḟEMBtN
     tN  on numbers 2,3,4...
   MB    map input to digits in base 2,3,4...
 ḟE      find first list that only has one unique element
L        length of that
```
[Answer]
# [APL (Dyalog Unicode)](https://www.dyalog.com/), ~~28~~ 26 bytes
Saved 2 bytes thanks to Adám!
```
{⌈/≢¨⍵/⍨1=≢∘∪¨⍵}⊢⊥⍣¯1⍨¨1+⍳
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24TqRz0d@o86Fx1a8ah3q/6j3hWGtkDeo44ZjzpWgcVqH3UtetS19FHv4kPrDYHyh1YYaj/q3QzUDZLebGjIlaZgZAYkzIyBhKGBkTEA "APL (Dyalog Unicode) – Try It Online")
Pretty straightforward implementation.
```
{⌈/≢¨⍵/⍨(1=≢∘∪)¨⍵}⊢⊥⍣¯1⍨¨1+⍳
                           1+⍳ ⍝ Make a range [2, n + 1]
                          ¨   ⍝ For each b in that range
                   ⊢⊥⍣¯1⍨    ⍝ Interpret n in base b (gives a vector of integers)
     ⍵/⍨                      ⍝ Keep the representations where
         1=≢∘∪¨⍵             ⍝ it's a repdigit
              ¨⍵             ⍝ For every representation,
          ≢∘∪                 ⍝ is the length of it, without duplicates
        1=                    ⍝ equal to 1?
   ≢¨                         ⍝ Get the length of each of the remaining representations
 ⌈/                           ⍝ Get the biggest length
```
[Answer]
# Mathematica, 58 bytes
```
FirstCase[#~IntegerDigits~Range[#+1],l:{a_ ..}:>Tr[1^l]]&
```
Throws an error (because base-1 is not a valid base), but it is safe to ignore.
Of course, it is okay to take the length of the first repdigit (`FirstCase`), since numbers in lower bases cannot be shorter than in higher bases.
[Answer]
## CJam (17 bytes)
```
{_,2>3+fb{)-!}=,}
```
[Online test suite](http://cjam.aditsu.net/#code=qN%25%7B~%3AE%3B%0A%0A%7B_%2C2%3E3%2Bfb%7B)-!%7D%3D%2C%7D%0A%0A~E%3Do%7D%2F&input=1%201%0A2%201%0A3%202%0A4%202%0A5%202%0A6%202%0A7%203%0A8%202%0A9%202%0A10%202%0A11%202%0A26%203%0A63%206%0A1023%2010). This is an anonymous block (function) which takes an integer on the stack and leaves an integer on the stack.
Works with brute force, using `3` as a fallback base to handle the special cases (input `1` or `2`).
[Answer]
# [Perl 6](https://perl6.org), 49 bytes
```
{+first {[==] $_},map {[.polymod($^b xx*)]},2..*}
```
[Try it online!](https://tio.run/##FYpBCsIwAAS/socibV2CTTQqkpdIlYoGhIaE1END6dtjepjDzG74xFFnl7CzMHnZ22@cfljuxvSonivdEIqJ4Mfk/LuuHi/Mc9v0K6UQ7ZqnIaG25QrrIzpCEoo4EidCE2fiQlyJ7lDY9hK12lyq5pb/ "Perl 6 – Try It Online")
### Explanation
```
{                                               }  # A lambda.
                  map {                   },2..*   # For each base from 2 to infinity...
                        .polymod($^b xx*)          #   represent the input in that base,
                       [                 ]         #   and store it as an array.
  first {[==] $_},                                 # Get the first array whose elements
                                                   # are all the same number.
 +                                                 # Return the length of that array.
```
The [polymod](https://docs.perl6.org/routine/polymod) method is a generalization of Python's `divmod`: It performs repeated integer division using a given list of divisors, and returns the intermediate remainders.  
It can be used to decompose a quantity into multiple units:
```
my ($sec, $min, $hrs, $days, $weeks) = $seconds.polymod(60, 60, 24, 7);
```
When passing a lazy sequence as the list of divisors, `polymod` stops when the quotient reaches zero. Thus, giving it an infinite repetition of the same number, decomposes the input into digits of that base:
```
my @digits-in-base-37 = $number.polymod(37 xx *);
```
I use this here because it allows arbitrarily high bases, in contrast to the string-based [`.base`](https://docs.perl6.org/routine/base) method which only supports up to base 36.
[Answer]
## TI-BASIC, 37 bytes
```
Input N
For(B,2,2N
int(log(NB)/log(B
If fPart(N(B-1)/(B^Ans-1
End
```
Prompts for N, returns output in Ans.
# Explanation
As an overview, for each possible base B in sequence it first calculates
the number of digits of N when represented in base B, then checks whether N is divisible by the value represented by that same number of 1-digits in base B.
```
Input N            Ask the user for the value of N.
For(B,2,2N         Loop from base 2 to 2N. We are guaranteed a solution
                   at base N+1, and this suffices since N is at least 1.
int(log(NB)/log(B  Calculate the number of digits of N in base B,
                   placing the result in Ans.
                   This is equivalent to floor(log_B(N))+1.
          (B-1)/(B^Ans-1   The value represented by Ans consecutive
                           1-digits in base B, inverted.
If fpart(N         Check whether N is divisible by the value with Ans
                   consecutive 1-digits, by multiplying it by the inverse
                   and checking its fractional part.
                   Skips over the End if it was divisible.
End                Continue the For loop, only if it was not divisible.
                   The number of digits of N in base B is still in Ans.
```
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), 24 bytes
```
{|/x{#{1=#?x}#y\x}'2+!x}
```
[Try it online!](https://ngn.codeberg.page/k#eJw1j1tugzAQRf9nFVRUaqPKMbaDSbDaLiRFCgLzUChOwZWMKF17oRN/nTN3rjSaKp1/qJvDmb2G724Jpw+3PPGXB7cA2HR+PE+/Q1oFQeDUxVzV86XK2045Nalhly1gz0yxbAVHCMU3HBAxQiISJTYccTohWHQnQ3KJLSmUxD0XikUZAIXG2tuYUlqYUtemq/ajzYurdkWT97XeF+aTfn3r0bamHykTSZLEtGr7kthGk86sndGSQd9I2datBWDrW+QtYMC9CBQOBy+xF+klQRFw9MnJC4u8sLtwiV0p/gMJ2z/bqegPBNpgBQ==)
* `x{...}'2+!x` call the inner `{...}` lambda on the input `n`, paired up with each number from `2..n+1`
	+ `y\x` convert the input to the current base
	+ `{1=#?x}#` filter down to representations containing only a single unique digit
	+ `#` return the length of this representation (`0` if it contained multiple digits)
* `{|/...}` return the maximum across all potential bases
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 13 bytes
```
lhf!t{TjLQ}2h
```
[Try it online!](http://pyth.herokuapp.com/?code=lhf%21t%7BTjLQ%7D2h&input=7&debug=0)
[Answer]
# Java 8, 111 bytes
```
n->{int r=0,i=1,l;for(String t;++i<n+2;r=(l=t.length())>r&t.matches("(.)\\1*")?l:r)t=n.toString(n,i);return r;}
```
Byte-count of 111 is also a rep-digit. ;)
**Explanation:**
[Try it here.](https://tio.run/##fZExb8IwEIX3/opThsqug0WClAFjOncoC2Pp4AYTTM0FOQdShfjtqUNS0QEh2Trd83f2e/LOnMyoPljcrb/b0pumgXfj8PwE4JBs2JjSwqJrrwKU7C3KlQ2AXEX1EndcDRlyJSwAQUOLo/m5g4Mep05nqVebOrAlBYcVkBLCzVDkKmjmNUlvsaIt43wenknuDZVb27CESb5aZS8Jf/XTwEmjpLq/gmHquAqWjgEhqEurehOH45ePJgYvp9qtYR@zDA9/fILhfZDOTecvelPgZjrrihDDKcDypyG7l/WR5CGOkkfmQEAyhSQWlCVz/Jq@z393IMmLG54Xf/w9spjcyGLyiMzG@T@26/jwC5f2Fw)
```
n->{                            // Method with Integer as parameter return-type
  int r=0,                      //  Result-integer
      i=1,                      //  Index-integer
      l;                        //  Length-integer
  for(String t;                 //  Temp-String
      ++i<n+2;                  //  Loop from 2 to `n+2` (exclusive)
      r=                        //    After every iteration, change `r` to:
        (l=t.length())>r        //     If the length of `t` is larger than the current `r`
        &t.matches("(.)\\1*")?  //     and the current `t` is a rep-digit:
         l                      //      Change `r` to `l` (the length of the rep-digit)
        :                       //     Else:
         r)                     //      Leave `r` as is
    t=n.toString(n,i);          //   Set String representation of `n` in base-`i` to `t`
                                //  End of loop (implicit / single-line body)
  return r;                     //  Return the result-integer
}                               // End of method
```
[Answer]
# Java 8, 79 bytes
A lambda from `Integer` to `Integer`.
```
n->{int m,b=2,l;for(;;b++){for(m=n,l=0;m>0&m%b==n%b;l++)m/=b;if(m<1)return l;}}
```
## Ungolfed lambda
```
n -> {
    int m, b = 2, l;
    for (; ; b++) {
        for (m = n, l = 0; m > 0 & m % b == n % b; l++)
            m /= b;
        if (m < 1)
            return l;
    }
}
```
Checks radices in increasing order from 2 until a rep-digit radix is found. Relies on the fact that the smallest such radix will correspond to a representation with the most digits.
`m` is a copy of the input, `b` is the radix, and `l` is the number of digits checked (and ultimately the length of the radix-`b` representation).
[Answer]
## Burlesque, 24 bytes
(see correct solution below)
```
J2jr@jbcz[{dgL[}m^>]
```
See in [action](http://cheap.int-e.eu/~burlesque/burlesque.cgi?q=7J2jr%40jbcz%5B%7BdgL%5B%7Dm%5E%3E%5D).
```
J2jr@ -- boiler plate to build a list from 2..N
jbcz[ -- zip in N
{dgL[}m^ -- calculate base n of everything and compute length
>]    -- find the maximum.
```
At least if my intuition is right that a rep-digit representation will always be longest? Otherwise uhm...
```
J2jr@jbcz[{dg}m^:sm)L[>]
:sm -- filter for "all elements are the same"
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 60 bytes
```
->n{(2..n).filter_map{d=n.digits _1
!d.uniq[1]&&d.size}.max}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3bXTt8qo1jPT08jT10jJzSlKL4nMTC6pTbPP0UjLTM0uKFeINuRRT9ErzMgujDWPV1FL0ijOrUmv1chMraqFm2BYouEWbxyooK-jaKRhzgXhGZihcM2Mo1wzMNTQwggkYGkAMWbAAQgMA)
]