| Bytes | Lang | Time | Link |
|---|---|---|---|
| 043 | C gcc | 251003T144216Z | jdt |
| 051 | Rust | 251008T170021Z | ShadowRa |
| 021 | GolfScript | 251009T025242Z | manatwor |
| 233 | Python 2 33 Bytes | 251007T015042Z | Random D |
| 039 | Desmos | 251005T202341Z | Aiden Ch |
| 041 | Swift 6.1 | 251004T233549Z | macOSist |
| 010 | Uiua | 251004T133401Z | aaa |
| 107 | Lua | 250930T144840Z | Someone |
| 026 | Ruby | 250928T041438Z | Jordan |
| 076 | Vim | 250930T143203Z | Aaroneou |
| 050 | Java | 250930T084245Z | Kevin Cr |
| 038 | R | 250930T020016Z | Giuseppe |
| 065 | PowerShell Core | 250929T191251Z | Julian |
| 106 | Excel | 250929T144137Z | tufbyte |
| 003 | 05AB1E | 250929T024443Z | Lucenapo |
| 033 | x8664 machine code | 250928T164909Z | m90 |
| 013 | APLNARS | 250928T073903Z | Rosario |
| 031 | Google Sheets | 250928T065317Z | doubleun |
| 022 | Wolfram Language Mathematica | 250928T065258Z | Greg Mar |
| 021 | Juby | 250928T041746Z | Jordan |
| 008 | cQuents | 250928T034331Z | Stephen |
| 041 | R | 250927T194737Z | M-- |
| 057 | Retina | 250927T232308Z | Neil |
| 005 | Japt | 250927T223704Z | Shaggy |
| 011 | Pyth | 250927T182029Z | Manish K |
| 029 | Python | 250927T174147Z | 97.100.9 |
| 006 | Charcoal | 250927T150323Z | Neil |
| 003 | Jelly | 250927T141736Z | Jonathan |
| 003 | Vyxal | 250927T141302Z | lyxal |
| 031 | JavaScript ES6 | 250927T140236Z | Arnauld |
C (gcc), 43 bytes
f(s){strtol(s,0,10-strcspn("98765432",s));}
strtol puts its result in eax/rax (x86 return register); f leaves it untouched, so caller sees it as return.
- -2 bytes thanks to @c--
Rust, 51 bytes
|n|(2..).find_map(|b|u64::from_str_radix(n,b).ok())
- Accepts input as a string (
&strspecifically, Rust's unowned reference to string data) - Returns an
Option<u64>(Acceptable per this meta post as it's infallible; it's never returningNone, alwaysSome(u64)) - Invalid inputs will parse in bases >10 if possible, all other invalid inputs and inputs representing numbers too large for
u64(in smallest base) panic.
Rust solution differs from most other languages in that Rust makes it comparatively verbose to convert back and forth between types (e.g. to get the byte values of a str, even just to extract the highest ordinal in it; to coerce the resulting byte value to a valid radix, since the bytes are u8s, but the radix must be u32), but makes both iterating over an infinite range of values and discarding failures fairly succinct (when ? is an option, or in this case, with iterator methods that filter by Option, with .ok() being a cheap way to convert from a Result), so this EAFP-style code (attempts to convert in each base until it finds one that works) is shorter than similar LBYL code (prechecks to find minimal valid base) used in most languages, which ends up five bytes longer expressed in Rust:
Rust, 56 bytes
|n|u64::from_str_radix(n,n.bytes().max()?as u32-47).ok()
GolfScript, 21 characters
.[{48-}/]\$)47-\;base
Sample run:
bash-5.2$ echo -n 32021 | ruby golfscript.rb <( echo '.[{48-}/]\$)47-\;base' )
905
Python 2 33 Bytes
lambda x:int(`x`,int(max(`x`))+1)
Finds the largest digit in the number, adds 1 to it, and uses it as the base. Then uses int to it turn into decimal.
Desmos, 39 bytes
f(L)=total(Lmax(L+1)^{[L.count-1...0]})
Takes input as a list of digits. Returns an integer.
Swift 6.1, 41 bytes
{Int($0+"",radix:Int("\($0.max()!)")!+1)}
Try it on SwiftFiddle! Type is (String) -> Int; assumes the input is a string containing a base-10 integer.
Uiua, 10 chars
⌝⊥+1⊸/↥⊥10
⊥10 converts a number into an array of its digits in base 10
+1⊸/↥ finds the largest number in the array and adds 1 to the result, keeping the array on the stack
⌝⊥ converts an array of digits to a number, taking the base as the first argument
Lua, 111 110 107 bytes
Once again, Lua proves why it's a horrible language for good golfing.
Addendum: using table.sort instead of math.max saves a byte‽ Neat!
Addendum 2: …W H Y I S I O S M A L L E R
n=io.read()t={}n:gsub(".",function(c)table.insert(t,tonumber(c))end)table.sort(t)print(tonumber(n,t[#t]+1))
Vim, 76 bytes
:s/./&\r/g|g/^/m0
:sor
G<C-a>^y$uu:g//norm@=line('.')<C-v>
a*<C-r>0<C-v><Esc>3hD
:%s/\n/+
C<C-r>=<C-r>-0
:s/./&\r/g # Add a newline after each digit, and...
g/^/m0 # ...reverse their order
:sor # Sort all lines
G # Jump to the last line (the highest digit)
<C-a>^y$ # Increment and copy to the 0 register (this is the base)
uu # Undo the increment and sort
:g//norm # On every digit...
a*<C-r>0<C-v><Esc> # ...append '*<base>'...
@=line('.')<C-v> # ...<digit position> times
3hD # We appended a couple extra times, so delete the extras
# Each line now looks like, e.g. 1*2*2*2*2*2*2
:%s/\n/+ # Join each line with '+'
C # Delete everything into the '-' register and insert...
<C-r>-0 # ...the '-' register (w/ an extra 0 to cancel an extra '+')...
<C-r>= # ...executed as an expression
# The final expression was, e.g. 1*2*2*2*2*2*2+0*2*2*2*2*2+1*2*2*2*2+1*2*2*2+0*2*2+1*2+0+0
💎
Created with the help of Luminespire.
Java, 50 bytes
n->Long.parseLong(n,n.chars().max().orElse(0)-47);
Explanation:
n-> // Method with String parameter and long return-type
Long.parseLong(n, // Return the input-string parsed to base:
n.chars() // Convert the input to an IntStream of its codepoints
.max() // Get its max codepoint
.orElse(0) // Convert it from an OptionalInt to an int
// (`.orElse(#)` is 1 byte shorter than `.getAsInt()`)
-47); // -48 to convert the codepoint to a digit,
// then +1 to convert that digit to the correct base
R, 38 bytes
\(n)min(mapply(strtoi,n,2:10),na.rm=T)
mapply as a version of Map that simplifies to array is the trick!
R, 42 bytes
\(n)min(Vectorize(strtoi)(n,2:10),na.rm=T)
Test harness taken from M--'s answer.
Frustratingly, this is a byte longer! Naively tries each base, then takes the minimum of the non-missing values. Vectorize is rarely used for golfing, but is shorter than sapply since we want to vectorize over the second argument.
PowerShell Core, 65 bytes
(($a=$args)|%{"$(1+($a|sort)[-1])*"*$j++ +$a[-++$i]})-join'+'|iex
Expects a list of digits using splatting
Returns an integer
Builds a base conversion expression and executes it:
For example 70707 becomes 7 + 8*0 + 8*8*7 + 8*8*8*0 + 8*8*8*8*7 which evaluates to 29127
Excel, 106 bytes
=SUM(--MID(A1,SEQUENCE(LEN(A1)),1)*(MAX(--MID(A1,SEQUENCE(LEN(A1)),1))+1)^SEQUENCE(LEN(A1),,LEN(A1)-1,-1))
Ungolfed version:
=LET(
s, A1, // the input as text
n, LEN(s), // number of digits
d, --MID(s, SEQUENCE(n), 1), // array of digits
b, MAX(d) + 1, // smallest valid base
SUM( d * b ^ SEQUENCE(n, 1, n-1, -1) )
)
x86-64 machine code, 33 bytes
97 31 FF 8D 77 0A 56 99 F7 F6 52 39 FA 0F 47 FA 85 C0 75 F3 FF C7 A9 F7 E7 01 C8 59 39 F1 75 F7 C3
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes a 32-bit integer in EDI and returns a 32-bit integer in EAX.
In assembly:
f: xchg eax, edi # Switch the number into EAX.
xor edi, edi # Set EDI to 0 by XORing it with itself.
lea esi, [rdi + 10] # Set ESI to 10.
push rsi # Push RSI (10) onto the stack as a sentinel.
r0: cdq # Sign-extend EAX, setting up for the next instruction.
div esi # Divide by ESI (which is 10);
# put the quotient in EAX and the remainder in EDX.
push rdx # Push RDX (contains EDX; a digit) onto the stack.
cmp edx, edi # Compare the digit to EDI.
cmova edi, edx # If the digit is greater, set EDI to that value.
test eax, eax # Check the value of the quotient.
jnz r0 # Jump back, to repeat, if it's nonzero.
inc edi # Add 1 to the highest digit (in EDI) to get the base.
.byte 0xA9 # Bypass the next two instructions by absorbing them into
# the 32-bit immediate operand of a TEST instruction.
r1: mul edi # Multiply EAX by EDI.
add eax, ecx # Add ECX to EAX.
pop rcx # Pop a value from the stack into RCX (contains ECX).
cmp ecx, esi # Compare the value to ESI, which is still 10.
jne r1 # Jump back, to repeat, if they are not equal.
ret # Return.
APL(NARS), 13 chars
k⊥⍨1+⌈/k←⍎¨⍕⎕
It result:
10⊥1 2 3
123
16⊥1 2 3
291
test:
k⊥⍨1+⌈/k←⍎¨⍕⎕
⎕:
1234
194
k⊥⍨1+⌈/k←⍎¨⍕⎕
⎕:
1011010
90
k⊥⍨1+⌈/k←⍎¨⍕⎕
⎕:
56789
56789
Google Sheets, 31 bytes
=decimal(join(,1:1),1+max(1:1))
Put the digits in row 1 and the formula in row 2.

To input an integer or string instead (42 bytes):
=decimal(A1,1+sort(mid(A1,row(A:A),1),1,))

Wolfram Language (Mathematica), 22 bytes
FromDigits[#,1+Max@#]&
Try all test cases online! Unnamed function taking a list of digits as input and outputting an integer. Same algorithm as many other answers.
cQuents, 8 bytes
K$;1+MD$
Runs a bit slow for big inputs.
Explanation
: implicit mode sequence : given input n, output the nth term in the sequence
each term equals
K ; ) from base ( , )
$ current index
1+ 1 +
M ) max ( )
D ) digits ( )
$ current index
R, 45 41 bytes
A different solution using strtoi():
\(n)strtoi(n,max(utf8ToInt(paste(n))-47))
If we assume character inputs, then it'd be 34 bytes:
\(s)strtoi(s,max(utf8ToInt(s)-47))
R, 59 58 bytes
\(n,b=utf8ToInt(paste(n))-48)sum(b*max(b+1)^rev(seq(b)-1))
Retina, 57 bytes
^
$'¶0_
O`\G.
+`(.¶)(.+)_(.)
$1$.($2*$1*_$2*_$3*)_
.+¶|_
Try it online! Link includes test cases. Explanation:
^
$'¶0_
Duplicate the input and prefix 0_ to the second copy.
O`\G.
Sort the digits in the first copy.
+`(.¶)(.+)_(.)
$1$.($2*$1*_$2*_$3*)_
Using the last digit in the first copy, convert the second copy from the desired base a digit at a time. Arithmetically, it behaves something like while d:l,r,d[:1]=l,(r*l+r+d[:1]),[].
.+¶|_
Delete the first copy and the _ marker.
Pyth, 11 bytes
iz+1seS.Pz1
Explanation
z # Input
.P 1 # All lists of elements of length 1
S # Sort
e # Last element
s # Convert to int
+1 # Add 1 with
i # Convert from base
z # Input
Charcoal, 6 bytes
I↨θ⊕⌈θ
Try it online! Link is to verbose version of code. Explanation:
θ Input string
↨ Convert from base
θ Input string
⌈ Maximum
⊕ Incremented
I Cast to string
Implicitly print
Jelly, 3 bytes
ḅ‘Ṁ
A monadic Link that accepts the number as a list of its base ten digits and yields the value of those digits interpreted in the smallest valid base.
Try it online! Or see the test-suite.
How?
ḅ‘Ṁ - Link: list of integers, D (N in base ten) e.g. [ 3, 2, 0, 2, 1]
‘ - increment each digit of {D} [ 4, 3, 1, 3, 2]
ḅ - convert {D} from {those} bases [905, 304, 8, 304, 69]
Ṁ - maximum of {those} 905
Note that Jelly will happily convert a list of digits containing numbers greater than the base, e.g. [8, 2, 7] converted from base three will evaluate \$8 \cdot 3 ^ 2 + 2 \cdot 3 ^ 1 + 7 \cdot 3 ^0 = 85\$.
Vyxal, 3 bytes
G›β
Takes input as a list of digits, outputs the desired number.
Explained
G›β
β # Input from base:
G # biggest digit
› # + 1
JavaScript (ES6), 31 bytes
Expects a string, returns an integer.
s=>parseInt(s,Math.max(...s)+1)
