Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Modified 2 days ago
Viewed 1k times
20
\$\begingroup\$

Let us define the operation of rebasing a number as writing out its digits in decimal form, then interpreting them in the smallest base N possible (2 <= n <= 10). For example, rebasing the number 1234 gives 194, since the smallest base that "1234" can be interpreted in is base 5, and "1234" interpreted in base 5 is 194 in decimal.

Challenge

Given a positive integer n, output n rebased as a decimal integer.

Expected output

Below is a list of the results of rebasing each number from 1 to 200:

1,2,3,4,5,6,7,8,9,2,3,5,7,9,11,13,15,17,19,6,7,8,11,14,17,20,23,26,29,12,13,14,15,19,23,27,31,35,39,20,21,22,23,24,29,34,39,44,49,30,31,32,33,34,35,41,47,53,59,42,43,44,45,46,47,48,55,62,69,56,57,58,59,60,61,62,63,71,79,72,73,74,75,76,77,78,79,80,89,90,91,92,93,94,95,96,97,98,99,4,5,11,19,29,41,55,71,89,109,6,7,14,23,34,47,62,79,98,119,15,16,17,27,39,53,69,87,107,129,28,29,30,31,44,59,76,95,116,139,45,46,47,48,49,65,83,103,125,149,66,67,68,69,70,71,90,111,134,159,91,92,93,94,95,96,97,119,143,169,120,121,122,123,124,125,126,127,152,179,153,154,155,156,157,158,159,160,161,189,190,191,192,193,194,195,196,197,198,199,18

And some more cases:

in      => out
1011010    90
10201      100
32021      905
11014      759
12345      1865
4326       1539
70707      29127
8314       6088
56789      56789

This is .

Note that this is OEIS entry A068505.

\$\endgroup\$

30 Answers 30

10
\$\begingroup\$

Python, 29 bytes

lambda x:int(x,int(max(x))+1)

Attempt This Online!

Assumes input is a string, outputs an integer.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Considering that he challenge reads "Given a positive integer n, output n rebased as a decimal integer.", you may wanna use str() on an integer input. \$\endgroup\$
    M--
    –  M--
    2025-09-27 23:07:23 +00:00
    Commented Sep 27 at 23:07
  • 8
    \$\begingroup\$ @M-- I/O formats on CGCC are typically lax, and in the case of opting into string input especially it would be strange to forbid in a function submission when a full program would have no other choice! \$\endgroup\$
    Unrelated String
    –  Unrelated String
    2025-09-27 23:35:48 +00:00
    Commented Sep 27 at 23:35
  • \$\begingroup\$ @UnrelatedString I admit that I am not familiar with the norms yet; anyway, it's only 5 additional bytes: lambda x:int(x,int(max(str(x)))+1). \$\endgroup\$
    M--
    –  M--
    2025-09-27 23:52:32 +00:00
    Commented Sep 27 at 23:52
  • \$\begingroup\$ @M--: It's one of the flexibilities granted for input and output, applying broadly to any submission, in any language. No reason to waste five bytes on str() wrapping when you're allowed to assume a str input. \$\endgroup\$
    ShadowRanger
    –  ShadowRanger
    2025-10-08 17:14:28 +00:00
    Commented Oct 8 at 17:14
8
\$\begingroup\$

JavaScript (ES6), 31 bytes

Expects a string, returns an integer.

s=>parseInt(s,Math.max(...s)+1)

Try it online!

Rebasing from 1 to 200

\$\endgroup\$
7
\$\begingroup\$

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\$.

\$\endgroup\$
6
\$\begingroup\$

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

Try it online!

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.
\$\endgroup\$
5
\$\begingroup\$

Vyxal, 3 bytes

G›β

Try it Online!

Takes input as a list of digits, outputs the desired number.

Explained

G›β
  β  # Input from base:
G    # biggest digit
 ›   # + 1 
\$\endgroup\$
5
\$\begingroup\$

R, 38 bytes

\(n)min(mapply(strtoi,n,2:10),na.rm=T)

Attempt This Online!

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)

Attempt This Online!

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.

\$\endgroup\$
1
  • \$\begingroup\$ Looks good. Vectorize is not used enough for golfing or otherwise. Thanks for posting. \$\endgroup\$
    M--
    –  M--
    2025-09-30 02:03:06 +00:00
    Commented Sep 30 at 2:03
5
\$\begingroup\$

C (gcc), 43 bytes

f(s){strtol(s,0,10-strcspn("98765432",s));}

Try it online!

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--
\$\endgroup\$
4
\$\begingroup\$

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
\$\endgroup\$
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

R, 45 41 bytes

A different solution using strtoi():

\(n)strtoi(n,max(utf8ToInt(paste(n))-47))

Attempt This Online!

If we assume character inputs, then it'd be 34 bytes:

\(s)strtoi(s,max(utf8ToInt(s)-47))

Attempt This Online!


R, 59 58 bytes

\(n,b=utf8ToInt(paste(n))-48)sum(b*max(b+1)^rev(seq(b)-1))

Attempt This Online!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ You can use c(n,"") instead of paste for -1 byte. \$\endgroup\$
    pajonk
    –  pajonk
    2025-09-28 06:56:50 +00:00
    Commented Sep 28 at 6:56
  • 1
    \$\begingroup\$ I was only able to get to 42 but thought it was different enough to post anyway. \$\endgroup\$
    Giuseppe
    –  Giuseppe
    2025-09-30 02:01:20 +00:00
    Commented Sep 30 at 2:01
4
\$\begingroup\$

05AB1E, 3 bytes

Z>ö

Try it online!

Explanation: Get the largest digit, add 1 and convert using that base.

\$\endgroup\$
4
\$\begingroup\$

Java, 50 bytes

n->Long.parseLong(n,n.chars().max().orElse(0)-47);

Try it online.

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
\$\endgroup\$
4
\$\begingroup\$

Ruby, 26 bytes

-4 bytes thanks to Value Ink

->n{n.to_i n.bytes.max-47}

Attempt This Online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ n.bytes.max-47 for -4 \$\endgroup\$
    Value Ink
    –  Value Ink
    2025-09-30 16:50:28 +00:00
    Commented Sep 30 at 16:50
  • \$\begingroup\$ @ValueInk Thanks! \$\endgroup\$
    Jordan
    –  Jordan
    2025-10-01 14:37:28 +00:00
    Commented Oct 1 at 14:37
3
\$\begingroup\$

Pyth, 11 bytes

iz+1seS.Pz1

Try it online!

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
\$\endgroup\$
3
\$\begingroup\$

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.

\$\endgroup\$
3
\$\begingroup\$

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) )
)

output from MS Excel

\$\endgroup\$
2
  • \$\begingroup\$ Welcome to Code Golf. The ungolfed version is actually 21 bytes shorter than the golfed version when you remove whitespace. \$\endgroup\$
    doubleunary
    –  doubleunary
    2025-09-29 22:48:38 +00:00
    Commented Sep 29 at 22:48
  • \$\begingroup\$ Port of the Google Sheets answer (36 bytes): =DECIMAL(TEXTJOIN(,,1:1),1+MAX(1:1)) \$\endgroup\$
    doubleunary
    –  doubleunary
    2025-09-30 21:57:22 +00:00
    Commented Sep 30 at 21:57
3
\$\begingroup\$

PowerShell Core, 65 bytes

(($a=$args)|%{"$(1+($a|sort)[-1])*"*$j++ +$a[-++$i]})-join'+'|iex

Try it online!

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

\$\endgroup\$
3
\$\begingroup\$

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.

Try it online!

\$\endgroup\$
3
\$\begingroup\$

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))
\$\endgroup\$
3
\$\begingroup\$

Uiua, 10 chars

⌝⊥+1⊸/↥⊥10

pad

⊥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

\$\endgroup\$
2
\$\begingroup\$

Japt, 5 bytes

Takes input as a digit array.

ìUrÔÄ

Try it

\$\endgroup\$
2
\$\begingroup\$

cQuents, 8 bytes

K$;1+MD$

Try it online!

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
\$\endgroup\$
2
\$\begingroup\$

J-uby, 21 bytes

:to_i%(A|:max|Z|:+&1)

Attempt This Online!

\$\endgroup\$
2
\$\begingroup\$

Google Sheets, 31 bytes

=decimal(join(,1:1),1+max(1:1))

Put the digits in row 1 and the formula in row 2.

screenshot

To input an integer or string instead (42 bytes):

=decimal(A1,1+sort(mid(A1,row(A:A),1),1,))

screenshot

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

Desmos, 39 bytes

f(L)=total(Lmax(L+1)^{[L.count-1...0]})

Takes input as a list of digits. Returns an integer.

Try It On Desmos!

Try It On Desmos! - Prettfied

\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ If you just assume the input is a str, not an int (perfectly valid; it's a standard flexibility), you don't need the string conversions (via Py2's old `variablename` syntax to get a repr), and this ends up identical to the existing modern Python 3 answer: lambda x:int(x,int(max(x))+1) \$\endgroup\$
    ShadowRanger
    –  ShadowRanger
    2025-10-08 17:03:30 +00:00
    Commented Oct 8 at 17:03
2
\$\begingroup\$

Rust, 51 bytes

|n|(2..).find_map(|b|u64::from_str_radix(n,b).ok())

Attempt This Online!

  • Accepts input as a string (&str specifically, Rust's unowned reference to string data)
  • Returns an Option<u64> (Acceptable per this meta post as it's infallible; it's never returning None, always Some(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()

Attempt This Online!

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

GolfScript, 21 characters

.[{48-}/]\$)47-\;base

Sample run:

bash-5.2$ echo -n 32021 | ruby golfscript.rb <( echo '.[{48-}/]\$)47-\;base' )
905

Try it online! / Try all test cases online!

\$\endgroup\$

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.