A repdigit is a natural number that can be written solely by repeating the same digit. For example, 777
is a repdigit, since it's solely composed of the digit 7
repeated three times.
This isn't limited to simply decimal (base 10) numbers, however:
- Every Mersenne number (of the form Mn = 2n-1) is a repdigit when written in binary (base 2).
- Every number is trivially a repdigit when written in unary (base 1).
- Every number
n
can also trivially be written as the repdigit11
in basen-1
(for example,17
when written in hexadecimal (base 16) is11
, and3
when written in binary (base 2) is also11
).
The challenge here is to find other bases where the input number may be a repdigit.
Input
A positive integer x > 3
, in any convenient format.
Output
A positive integer b
with (x-1) > b > 1
where the representation of x
in base b
is a repdigit.
- If no such
b
exists, output0
or some falsey value. - If multiple such
b
exist, you can output any or all of them.
Rules
- The
(x-1) > b > 1
restriction is to prevent the trivial conversions to unary or the "subtract one" base. The output number can be written in unary or any convenient base, but the base itself must not be one of the trivial conversions. - Input/output can be via any suitable method.
- Standard loophole restrictions apply.
Examples
In --> Out
11 --> 0 (or other falsey value)
23 --> 0 (or other falsey value)
55 --> 10 (since 55 is 55 in base 10)
90 --> 14 (since 90 is 66 in base 14 ... 17, 29, 44 also allowed)
91 --> 9 (since 91 is 111 in base 9 ... 12 also allowed)
b ≤ 36
(many languages' built-in base conversion functions don't go higher)? \$\endgroup\$b ≤ 36
severely limits the scope of this problem, and all of the existing answers correctly handle larger bases, so I'm going to say no, you cannot assume an upper bound onb
beyond what's given. \$\endgroup\$