# What base is this number in?

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

• Can I output in base 36? Aug 23, 2016 at 4:42
• @LeakyNun Geez, I hope not. Aug 23, 2016 at 5:22
• @LeakyNun You must output this lowest possible base in decimal. Aug 23, 2016 at 6:09
• @RohanJhunjhunwala If that's your languages closest equivalent to a string, I don't see why not. Aug 23, 2016 at 6:16
• Usually unary is all 1s, and leading zeros are not standard for any positional-based numeric system. Aug 23, 2016 at 10:35

# Perl, 30 27 bytes

Includes +1 for -p

Run with the input on STDIN, e.g.

base.pl <<< codegolf


base.pl:

#!/usr/bin/perl -p
\@F[unpack"W*"];\$_=@F%39-9


## LiveScript, 32 bytes

->1+parseInt (it/'')sort!pop!,36


A port of this answer in my favorite language that compile to JavaScript. If base~number operator worked with variables I could write ->1+36~(it/'')sort!pop! (23 bytes), but it conflicts with the function bind operator :/

# PowerShell full program, 56 62 bytes

lowercase letters required.

([int]((read-host).ToCharArray()|sort|select -l 1)-8)%39


# R, 59 57 bytes

Thanks to @Andreï-Kostyrka for two bytes.

max(which(c(0:9,letters)%in%strsplit(scan(,""),"")[[1]]))


scan(,'') takes the input and coerces it to a string. Then strsplit divides it into its individual characters. [[1]] is because that returns a list. %in% then checks which of the vector 0,1,2,...,8,9,a,b,c,...,x,y,z is in the input. which tells us the place in that vector of items in the input -- and max finds the biggest place -- which corresponds to the base.

• Try removing the two extra spaces to save 2 bytes. Aug 29, 2016 at 10:12

# 05AB1E, 3 bytes

Hà>


Explanation:

          # implicit input
H         # convert each digit to decimal
à        # maximum
# implicit output



# Thunno 2G, 4 bytes

36b⁺


Try it online!

Takes input in uppercase.

#### Explanation

36b⁺  # Implicit input
36b   # Convert each character from base-36
⁺  # Increment each integer
# Implicit output of maximum