31
4
Here's a nice easy challenge:
Given a string that represents a number in an unknown base, determine the lowest possible base that number might be in. The string will only contain
0-9, a-z
. If you like, you may choose to take uppercase letters instead of lowercase, but please specify this. You must output this lowest possible base in decimal.
Here is a more concrete example. If the input string was "01234", it is impossible for this number to be in binary, since 2, 3, and 4 are all undefined in binary. Similarly, this number cannot be in base 3, or base 4. Therefore, this number must be in base-5, or a higher base, so you should output '5'.
Your code must work for any base between base 1 (unary, all '0's) and base 36 ('0-9' and 'a-z').
You may take input and provide output in any reasonable format. Base-conversion builtins are allowed. As usual, standard loopholes apply, and the shortest answer in bytes is the winner!
Test IO:
#Input #Output
00000 --> 1
123456 --> 7
ff --> 16
4815162342 --> 9
42 --> 5
codegolf --> 25
0123456789abcdefghijklmnopqrstuvwxyz --> 36
my language doesn't really support string input, may I accept input as ascii integers separated by newlines? – Rohan Jhunjhunwala – 2016-08-23T01:04:08.510
I know it seems a bit "unreasonable" so I doubt its ok – Rohan Jhunjhunwala – 2016-08-23T01:04:34.417
@RohanJhunjhunwala, what's your language? – Daniel – 2016-08-23T01:32:37.600
2
S.I.L.O.S https://github.com/rjhunjhunwala/S.I.L.O.S @Dopapp
– Rohan Jhunjhunwala – 2016-08-23T01:36:09.453In Python 3, could I take input as a byte string? – Dennis – 2016-08-23T02:25:02.977
8Can I output in base 36? – Leaky Nun – 2016-08-23T04:42:32.650
9@LeakyNun Geez, I hope not. – Dennis – 2016-08-23T05:22:15.997
4@LeakyNun
You must output this lowest possible base in decimal.
– James – 2016-08-23T06:09:38.5473@RohanJhunjhunwala If that's your languages closest equivalent to a string, I don't see why not. – James – 2016-08-23T06:16:08.380
@Peter, I was just looking for dupes, but I think http://codegolf.stackexchange.com/q/48952/8478 is a better fit?
– Martin Ender – 2016-08-23T07:37:28.697Although this is only a subset of the earlier question, it's a subset which is easy to extract.
– Peter Taylor – 2016-08-23T07:37:30.157@MartinEnder, you're right. Do you need me to retract my close vote, or are your powers sufficient without? – Peter Taylor – 2016-08-23T07:38:26.907
@PeterTaylor I can undo it myself, don't worry. (Although I do think the new spec is better than the old...) – Martin Ender – 2016-08-23T07:39:15.937
Wait actually, I'm not sure it's a dupe of either. This only asks for the base, not for the actual conversion... I'll reopen this and let the community decide, but I don't think we'd close a prime-testing challenge as a dupe of any other challenge requiring a primality test either. – Martin Ender – 2016-08-23T07:41:15.680
3Usually unary is all 1s, and leading zeros are not standard for any positional-based numeric system. – OrangeDog – 2016-08-23T10:35:21.913
Well, you lost me after the fourth test input. – Jesse C. Slicer – 2016-08-23T14:49:13.340
if for hex the Greater digit is F, than yes for 36 is Z – RosLuP – 2016-08-27T20:10:09.563