17
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 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]
1Asuming
base > 1
? – H.PWiz – 2017-08-05T21:02:23.970@H.PWiz Yes. base 1 doesn't really make any sense. – Post Rock Garf Hunter – 2017-08-05T21:02:46.467
...and
input >= 3
I guess :) – Jonathan Allan – 2017-08-05T21:05:23.863@JonathanAllan No, input can be as small as 1. Is there a problem with that? – Post Rock Garf Hunter – 2017-08-05T21:05:54.897
Oh OK, just makes 2 an edge case (the base being higher than the input) – Jonathan Allan – 2017-08-05T21:07:10.527
@JonathanAllan Yes 1 and 2 are edge cases, but to be clear you are not outputting the base with the longest rep digit just the length. – Post Rock Garf Hunter – 2017-08-05T21:08:07.080
2you can add test cases 63->6 and 1023->10 if you like – J42161217 – 2017-08-05T21:38:38.157
Rep-digits can use any digit, not just 1, right? I think it would be good to have more test cases to cover those. – xnor – 2017-08-06T02:11:26.880
1@WheatWizard I think 26 does it for instance, it's
222
in base 3. – xnor – 2017-08-06T02:15:10.267222,333,444,555,666,777,888,999
all work here are the first 69 if my code is correct (including the edge case of2
) – Jonathan Allan – 2017-08-06T02:31:29.690@xnor I must have made a mistake. I'll add that right away. :) – Post Rock Garf Hunter – 2017-08-06T02:37:37.640
1Can bases go above 10? If so, for bases > 10, should we include characters a-z? What about bases > 36? – Rick Hitchcock – 2017-08-06T11:20:43.483
6@RickHitchcock Bases can go arbitrarily high. Since you don't have to output any numbers in any base other than 10, I don't care how you represent other bases, but they should work for bases larger than 36. – Post Rock Garf Hunter – 2017-08-06T14:49:47.280