28
1
Given a positive integer n
, output the smallest base b >= 2
where the representation of n
in base b
with no leading zeroes does not contain a 0
. You may assume that b <= 256
for all inputs.
Test Cases
1 -> 2 (1)
2 -> 3 (2)
3 -> 2 (11)
4 -> 3 (11)
5 -> 3 (12)
6 -> 4 (12)
7 -> 2 (111)
10 -> 4 (22)
17 -> 3 (122)
20 -> 6 (32)
50 -> 3 (1212)
100 -> 6 (244)
777 -> 6 (3333)
999 -> 4 (33213)
1000 -> 6 (4344)
1179360 -> 23 ([12, 9, 21, 4, 4])
232792560 -> 23 ([15, 12, 2, 20, 3, 13, 1])
2329089562800 -> 31 ([20, 3, 18, 2, 24, 9, 20, 22, 2])
69720375229712477164533808935312303556800 -> 101 ([37, 17, 10, 60, 39, 32, 21, 87, 80, 71, 82, 14, 68, 99, 95, 4, 53, 44, 10, 72, 5])
8337245403447921335829504375888192675135162254454825924977726845769444687965016467695833282339504042669808000 -> 256 ([128, 153, 236, 224, 97, 21, 177, 119, 159, 45, 133, 161, 113, 172, 138, 130, 229, 183, 58, 35, 99, 184, 186, 197, 207, 20, 183, 191, 181, 250, 130, 153, 230, 61, 136, 142, 35, 54, 199, 213, 170, 214, 139, 202, 140, 3])
1What are the values for ten, eleven, etc. in higher bases you are using? Do they contain zeroes? – Stephen – 2017-10-25T19:05:48.387
@Stephen The OP talking about the array-based representations of them, not the actual string representation – Okx – 2017-10-25T19:06:24.107
19@Stephen The values chosen for digits above
9
do not matter, because they are not0
. – Mego – 2017-10-25T19:06:43.580Related. – Mr. Xcoder – 2017-10-25T19:33:21.140
9
This is OEIS A106370.
– Engineer Toast – 2017-10-25T19:36:59.423What if builtins can´t do base 1000? – Titus – 2017-10-25T20:12:27.057
1@Titus That's a good point. I'll limit the base to something reasonable. – Mego – 2017-10-25T20:13:21.480
you should probably explicitly say you can't use fractional part numbers (10 = 9.999..., 17000 = 17999.999...) – Destructible Lemon – 2017-10-25T22:04:59.640
Could you add a couple of test cases with larger (>36) outputs? – Shaggy – 2017-10-25T22:14:38.110
@DestructibleLemon Do you mean 17000=16999,999...? Because it's certainly not 17999,999... – Fabian Röling – 2017-10-26T09:45:11.170
@Shaggy I tested my MATL entry up to
1e6
, and didn't get beyond base20
atn=658370
– Sanchises – 2017-10-26T10:45:16.993The question title is misleading, and perhaps impossible. Don't all bases use zeros? Perhaps it should be "Smallest Base of Zeroless Representation". – CJ Dennis – 2017-10-27T03:25:00.720
@CJDennis You're reading too much into it. – Mego – 2017-10-27T03:25:27.500
@Shaggy I'm still searching for cases where
b > 20
. It's taking a while! – Mego – 2017-10-27T03:25:56.1571@Mego: Try 232792560. It's the lcm of 2,3,...,20, so in every base <= 20 it has a 0 as the least significant digit. – Nate Eldredge – 2017-10-27T13:49:25.033
While the larger test cases are interesting, are we required to handle them? If our language doesn't support extended integers, for example, or at least, not by default? – Conor O'Brien – 2017-10-27T20:30:36.080
@ConorO'Brien By the meta consensus, no. – Mego – 2017-10-27T20:30:59.587
@Mego Which meta consensus, for future reference? – Conor O'Brien – 2017-10-27T20:47:52.640
@ConorO'Brien There's not a hard consensus, but the answers to this question all share the same idea that cases where the input and/or output exceed the language's representable range need not be considered.
– Mego – 2017-10-27T20:49:14.797