# Question
Title: Remove All Smalltalk Comments for Code Golf
* Take a line of input (function arguments or stdin, etc.).
* Remove comments in it, where a comment starts and ends with `"`.
* Do not remove comments in string literals, which start and end with `'`. String literals do not contain escapes, because smalltalk has nice, easily lexable syntax ;).
* Output this string.
* The number of `"`s not inside strings and the number of `'`s not in comments in the input are both guaranteed to be even.
* Because removing comments makes programs more golfy, this is : shortest code per language wins.

## Examples

`input => output`

```
123 => 123
1"2"3 => 13
1""23 => 123
'12' => '12'
'1"2'3"" => '1"2'3
'1"2"3' => '1"2"3'
a"1'2'3"a => aa
"a"b"c" => b
'a'b'c' => 'a'b'c'
a'"'b'"'c => a'"'b'"'c
a"'"b"'"c => abc

```
 Regex is boring as usual. Try something new, or answer in smalltalk!

# Answer
# Smalltalk, 325 bytes

```
[:k|k inject:OrderedCollection new into:[:a :b|(a isEmpty not and:[a last=0])ifTrue:[(b=$')ifTrue:[a removeLast. a add:b. a]ifFalse:[a removeLast. a add:b. a add:0. a]]ifFalse:[(a isEmpty not and:[a last=$"])ifTrue:[(b=$")ifTrue:[a removeLast. a]ifFalse:[a]]ifFalse:[(b=$')ifTrue:[a add:b. a add:0. a]ifFalse:[a add:b. a]]]]]

```

Some hot garbage smalltalk code.

It essentially uses a stack, pushing a `0` for a placeholder for when it sees `'`. When it sees `"`, it keeps in on the top of the stack until it sees another `"`.

I couldn't get an Eval function (smalltalk docs are *terrible*), nor could I get regex to work (smalltalk docs are *terrible*).

You can use GNU Smalltalk to run this, in theory, although I only tested it on the online compiler (linked above).

Here's a (more) readable version that takes from stdin and writes to stdout. As you can tell smalltalk is a beautiful language...

```
Transcript show:(stdin nextLine inject:
    OrderedCollection new into:
        [:a :b|

        Transcript show: a printString; cr.

        (a isEmpty not and:[a last = 0])ifTrue: [
            (b = $') ifTrue: [
                a removeLast.
                a add: b.
                a
            ] ifFalse:[
                a removeLast.
                a add: b.
                a add: 0.
                a
            ]
        ] ifFalse: [
            (a isEmpty not and:[a last = $"]) ifTrue: [
                (b = $") ifTrue: [
                    a removeLast.
                    a
                ] ifFalse: [a]
            ] ifFalse: [
                (b = $') ifTrue: [
                    a add: b.
                    a add: 0.
                    a
                ] ifFalse: [
                    a add: b.
                    a
                ]
            ]
        ]
]).

```

Note: the regex solution almost works, using the same approach as Jakque, but it fails since smalltalk gives `nil` instead of an empty string:

```
Transcript show:(stdin nextLine replacingAllRegex: '".*?"|(''.*?''|.)' with: '%1')

```
> 9 votes

# Answer
# APL (Dyalog Extended), ~~30~~ 26 bytes (SBCS)

Anonymous prefix lambda.

```
{⍵/⍨≠\⍛⍱⍨<⌿≠\@1⊢'''"'∘.=⍵}

```

Try it online!

`{``}`dfn; argument is :
``a"1'2'3"a'1"2"3'a"'"b"'"c``

`'''"'∘.=⍵` equality table for `'` and `"` versus the argument
`[[0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1,0,0,0,1,0,0],`
`[0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0]]`

`≠\@1⊢` running parity (lit. XOR scan) **at** the 1st row (lit XOR scan) indicating characters inside strings
`[[0,0,0,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,1,1,1,1,0,0,0],`
`[0,1,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0]]`

`<⌿` second row, i.e. comment delimiters, and not first row, i.e. inside string, i.e. active comment delimiters (lit. vertical less-than reduce)
`[0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0]`

`≠\⍛⍱⍨` neither that (active comment delimiters) NOR its running parity (inside comments)
`[1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1]`

`⍵/⍨` use that to filter the characters of the argument
``aa'1"2"3'ac``
> 6 votes

# Answer
# Jelly, 48 bytes

```
iⱮ⁾'"o1:0¤>/
ṣ”"2œPj€”"µẹ”'2ị‘œṖµÇ?;ß}¥/$¹f⁾'"$?

```

Try it online!

This is definitely not the best approach, even considering Jelly is typically not great with strings.

iⱮ⁾'"o1:0¤>/  Helper Link
iⱮ⁾'"         Find the first ' and "; 0 if not found
     o        Logical OR with
      1:0¤    1 / 0 (infinity) - that way, "not found" is at the end, not the start
          >/  Is the first greater than the second?

ṣ”"2œPj€”"µẹ”'2ị‘œṖµÇ?;ß}¥/$¹f⁾'"$?  Main Link
                                  ?  If
                             f⁾'"$   There are any ' or "
                     ?     $         - If
                    Ç                - " was found first
ṣ”"                                    - Split on "
   2œP                                 - Split over and discard the second item
      j€”"                             - Join each of those with " (basically, this slices out
                                         the part between and including the first and second ",
                                         and leaves the part before and after as two sublists)
                                     - Otherwise
           ẹ”'                         - Find all indices of '
              2ị                       - Get the second of these
                ‘                      - And increment it
                 œṖ                    - And partition the list at that point (basically, this
                                         divides the list at the second ' without removing anything)
                         ¥/          - Then, reduce (apply to first and second as left and right) by
                      ;ß}            - Concatenating the left side with this function applied to the right link
                            ¹        Otherwise, if ' and " aren't found, just return the string itself
```
</code></pre>
> 6 votes

# Answer
# Jelly, 17 bytes

```
⁾'"iⱮnaoɗ\ŻṖoƊỊx@

```

Try it online!

A link taking a Jelly string argument and returning a Jelly string without the comments.

## Explanation

```
⁾'"iⱮ              | Positions of each character in '" (so single quote -> 1, double quote -> 2, anything else -> 0)
         ɗ\        | Cumulative reduce (x,y)
     nao           | - (x != y) and (x or y)
              Ɗ    | Following as a monad:
           Ż       | - Prepend zero
            Ṗ      | - Remove last item from list
             o     | - Or
               Ị   | Less than or equal to 1
                x@ | Original input with 0 or 1 copies of each character as appropriate

```
> 5 votes

# Answer
# QuadR `g`, ~~18~~ 12 bytes

‒6 thanks to Neil.

```
'.*'
".*"
&

```

Try it online!

This is equivalent to the Dyalog APL function `'''.*''' '".*"'⎕R'&' ''⍠'Greedy'0`

The `g` flag turns off greedy patterns, essentially making `*` mean `*?`. Then the two patterns simply replace `'.*'` strings and `".*"` comments with `&` themselves and  nothing, respectively.
> 4 votes

# Answer
# C, ~~92~~ 91 bytes

```
c;s;main(){while((c=getchar())+1)s=s?s-2?putchar(c):0,s*(c!=44-5*s):c-34?putchar(c)==39:2;}

```

All my submissions so far have been in esolangs, so even though C might not be anything groundbreaking, it's at least new to me. :)

Try It Online!

### Explanation

```
c;s;                          // for current char and state
main() {
  while ((c=getchar())+1)     // while input is not EOF:
    s=s?            // if state is not 0 (0=default, 1=string literal, 2=comment)
      s-2?putchar(c):0,       // output the current char if state is not 2
      s*(c!=44-5*s) // set s to 0 if the relevant character is found
                    // (39 ['] if state = 1, 34 ["] if state = 2)
     :              // else (state = 0)
      c-34?         // if the current char is not ["]
        putchar(c)==39 // output current char, and if it is ['], set s to 1
       :      // else (current char is ["])
        2     // set s to 2
    ;}        // end expression, statement, and main function

```
> 4 votes

# Answer
# QBasic, ~~118~~ ~~113~~ 112 bytes

```
LINE INPUT s$
FOR i=1TO LEN(s$)
a=ASC(MID$(s$,i))
k=c
c=c XOR(a=34)<q
q=q XOR(a=39)<c
IF c+k=0THEN?CHR$(a);
NEXT

```

### Explanation

Looping over the ASCII code `a` of each character in a line of input `s$`, we track three boolean values:

* `c` is true inside a comment, false otherwise
* `q` is true inside quotes, false otherwise
* `k` is the previous iteration's value of `c` (we need to track this so we can suppress both double quotes instead of just the first one)

The values are updated as follows:

* If the current character is a double quote (`a=34`) and `q` is false, toggle `c`
* If the current character is a single quote (`a=39`) and `c` is false, toggle `q`

If both `c` and `k` are false, we're not in a comment, so output the character.

(There's a fun trick in the update statements: In QBasic, truthy is -1, so instead of `a=39AND c=0`, we can get the same result from `(a=39)<c`. The inequality will be true only when `a=39` is `-1` and `c` is `0`.)
> 4 votes

# Answer
# Python 3.8 (pre-release), no regex, ~~75~~ 65 bytes

```
a=b=1
for i in input():c=b*i;a^="'"==c;b^='"'==a*i;print(end=c*b)

```

Try it online!

Much cleaner solution than my previous one

### how it works :

`a` and `b` store the state of the string:

* `a` is equal to `0` if the char is inside a literal and `1` otherwise
* `b` is equal to `0` if the char is inside a comment and `1` otherwise
* `c` store the char multiplied by `b`. If the char is inside a comment (`b` is equal to `0`), `c` is equal to the empty string
* `a^=` use of the bitwise operator xor to swich the state of `a` if the current char is `'` and the char is not inside a comment
* same goes for `b` but with `"`
* `print(end=c*b)` print the char if `b` is not set to `0`. `end=` is for avoiding the trailing new line

# Python 3.8 (pre-release), regex, 52 bytes

```
lambda s:re.sub("\".*?\"|('.*?')","\\1",s)
import re

```

Try it online!

Pretty basic: I replace comments by nothing and literals by themselves. Regex substitution are not overriding. Lazy operators do the rest
> 3 votes

# Answer
# JavaScript (Node.js), 41 bytes

```
s=>s.replace(/('|").*?\1/g,_=>_<'%'?'':_)

```

Try it online!

Trivial, thank EliteDaMyth for -3 bytes

# JavaScript (Node.js), ~~88~~ 86 bytes, No RegEx

```
f=([c,...s],y=c=='"')=>c?[[c+s.splice(0,s.indexOf(c=="'"|y?c:s)+1).join``][+y]]+f(s):s

```

Try it online!

If `s.indexOf(s)` happens to be non-negative, then `s==c` and `f([c,c])==c+c`
> 2 votes

# Answer
# Retina 0.8.2, 16 bytes

```
('.*?')|".*?"
$1

```

Try it online! Link includes test cases. Explanation: Regex, obviously. Since by default matches can't overlap, the regex can match both strings and comments and won't get confused. It then remains to delete the comments without changing the strings.
> 2 votes

# Answer
# Charcoal, 28 bytes

```
≔ωζＦＳ«Ｆ¬⁼∨ζι"ι¿№"'ι≔⁻∨ζι∧ζιζ

```

Try it online! Link is to verbose version of code. Explanation:

```
≔ωζ

```

Keep track of the current quote character, initially , but can be `"` or `'`.

```
ＦＳ«

```

Loop over the input.

```
Ｆ¬⁼∨ζι"ι

```

If the current quote, or the current character if there is no current quote, is not `"`, then print the current character.

```
¿№"'ι

```

If the current character is a quote, then...

```
≔⁻∨ζι∧ζιζ

```

... turn the current quote on or off as appropriate.

* If the current quote is empty, then we subtract nothing from the current character, so the current quote becomes the current character.
* Otherwise, we subtract the current character from the current quote. This ends the current quote only once we find the matching character.
> 1 votes

# Answer
# Haskell, 105 bytes

```
f('"':s)=g s
f(a@'\'':s)=a:h s
f(a:s)=a:f s
f[]=[]
g('"':s)=f s
g(a:s)=g s
h(a@'\'':s)=a:f s
h(a:s)=a:h s

```

Try it online!
> 1 votes

# Answer
# TypeScript's type system, 142 bytes

```
type F<S>=S extends`'${infer Z}'${infer X}`?`'${Z}'${F<X>}`:S extends`"${any}"${infer X}`?F<X>:S extends`${infer C}${infer X}`?`${C}${F<X>}`:S

```

Try it at the TS playground!

This is a type F that takes and outputs a string type.

Explanation:

```
type F<S>=

```

This is the type signature for F. S is the input string type, but since this is a recursive type, S isn't necessarily the original string, but rather whatever part of the string we haven't processed yet.

```
S extends`'${infer Z}'${infer X}`?`'${Z}'${F<X>}`

```

Attempt to match S against: single quote + a string called Z + single quote + a string called X. If the match succeeded, return single quote + Z + single quote + recurse, with X as the argument.

This step keeps anything within single quotes.

```
:S extends`"${any}"${infer X}`?F<X>

```

If the match failed, attempt to match S against: double quote + a string + double quote + a string called X. If the match succeeded, recurse with X as the argument.

This step discards anything between double quotes.

```
:S extends`${infer C}${infer X}`?`${C}${F<X>}`

```

If that match failed, match S against: a character called C + a string called X. This basically just extracts the first character and the rest. If the match succeeded, return C + recurse with X as the argument.

```
:S

```

If that match failed, S must be the empty string, so we just return it because the program has finished.

Note that this solution isn't tail recursive, so it only works for strings under 50 characters. Here's a tail recursive version that works for strings up to 999 characters:

## TypeScript's type system, 166 bytes

```
//@ts-ignore
type F<S,O="">=S extends`'${infer Z}'${infer X}`?F<X,`${O}'${Z}'`>:S extends`"${any}"${infer X}`?F<X,O>:S extends`${infer C}${infer X}`?F<X,`${O}${C}`>:O

```

Try it at the TS playground!
> 1 votes

---
Tags: code-golf, string, balanced-string, comment
---


title: Write a microwave timer!

text:
# Question
Title: Write a microwave timer!
You are an employee of Microteque, a leading Silicon Valley startup creating smart microwave ovens for all kinds of strange places. Your customers can get their microwaves printed with patterns to match their kitchens, campers, man caves; even the kitchens of large nation-state facilities have shiny new branded microwave ovens.

Due to the cutting-edge nature of your microwave control board technology, you've ended up having to use the programming language MicrowaveX\* and you're working out how to program the time counter. Your counter looks like this:

Your goal is to write a program that takes the input time and translates it into the number of seconds that the microwave needs to run.

As input, the function must take a string in the format `##:##` (including the colon at position 3) and return an integer.

Please note that it should also be able to handle more than 60 seconds in the seconds slot.

Finally, due to some pesky regulations, you cannot have your microwave oven run for more than 100 minutes (6,000 seconds)

Sample inputs and outputs:

`01:30` --\> 90 seconds

`00:66` --\> 66 seconds

`01:99` --\> 159 seconds

`02:39` --\> 159 seconds

`99:99` --\> 6,000 seconds (capped at 100 minutes due to aforementioned regulations)

\*: MicrowaveX happens to be identical to your programming language of choice, but Microteque has rebranded it to sound more appealing to their investors.

# Answer
# Bash \+ GNU utilities, 33 bytes

```
dc<<<[6000]sL${1/:/ 60*}+dlLx\<Lp

```

Try it online!

Or try the test suite.

The input string is passed as an argument, and the output is on stdout.

---

**How it works**

First bash expands ${1/:/ 60\*} by taking argument 1 and replacing the `:` with `60*` (there's a space before the `60` that StackExchange isn't displaying here). For example, if the input is `01:30`, the expansion is `01 60*30`.

Also, `\<` gets used as the character `<` without its special meaning in the shell.

So what happens is that `dc` is run with

`[6000]sL`minutes`60*`seconds`+dlLx<Lp`

as its program (where "minutes" and "seconds" refer to the actual two-digit numbers).

This carries out the following operations:

```
[6000]               Definition of a macro which pushes 6000 on the stack.
sL                   Save the macro in register L.
minutes 60*seconds+  Compute minutes*60+seconds,
                        which is the total number of seconds.
d                    Duplicate the total number of seconds on the stack.
lLx                  Run macro L, which pushes 6000 on the stack.
                     The stack now looks like:
                        #seconds #seconds 6000
                        (top of stack on the right).
<L                   Pop 6000 and #seconds from the stack;
                        if 6000 < #seconds,
                          then run macro L to push 6000 on the stack again.
                     At this point, the item at the top of the stack is:
                        #seconds, if #seconds <= 6000,
                        6000, if #seconds > 6000.
p                    Print the top of the stack.

```
> 18 votes

# Answer
# Python 2, 42 bytes

```
lambda t:min(int(t[:2])*60+int(t[3:]),6e3)

```

Try it online!
> 12 votes

# Answer
# JavaScript (ES6), 42 bytes

```
s=>Math.min(6e3,+([m]=s.split`:`)[1]+m*60)

```

Try it online!

### Commented

```
s =>               // s = input string
  Math.min(        // return the minimum of ...
    6e3,           //   ... 6000 and the following result ...
    +(             //   coerce to integer:
      [m] =        //     store into m the number of minutes
        s.split`:` //     which is the first term of the array obtained
                   //     by splitting s on ':'
    )[1] +         //   yield the seconds (2nd term of the above array)
    m * 60         //   and add the seconds multiplied by 60
  )                // end of Math.min()

```
> 10 votes

# Answer
# Retina 0.8.2, ~~27~~ 24 bytes

```
\d+
$*
+`1:
:60$*
6000`1

```

Try it online!

**Explanation**

I'll use the input `01:30` as an example.

```
\d+
$*

```

Convert minutes and seconds to unary. For example, `01:30` would become `1:111111111111111111111111111111`.

```
+`1:
:60$*

```

Loop over each digit preceding the `:`, move it to the right of the `:`, and repeat the digit 60 times. The `01:30` example would now be `:1111111111111111111...` (90 ones)

```
6000`1

```

Count the first 6000 ones.
> 10 votes

# Answer
# Google Sheets, ~~32~~ 16 bytes

*Saved 16 bytes thanks to Chronocidal straight up commenting a better answer.*

```
=240*MIN(25,6*A1

```

Sheets will automatically add two trailing parentheses when you exit the cell. Input is in `A1`.

---

This could also be written as `Min(6000,86400*TimeValue("0:"&A1))` if we wanted to fully expand it and be precise. As it is, we take advantage of the fact that Sheets will interpret a string that looks like a time to be in the format `hh:mm` by default and treat it as a number of days. For instance, `=1*"12:00"` would return `0.5` and `=1*"6:00"` would return `0.25`. We can then divide by 60 to convert from `hh:mm` to `mm:ss`. If that's the only simplification we used, it would look like this:

```
=Min(6000,1440*A1

```

Dividing both `6000` and `1440` by 240 saves us 5 bytes inside the `Min()` function at a cost of only 4 bytes outside of it.
> 10 votes

# Answer
# C (gcc), ~~61~~ 50 bytes

Saved a whopping 11 bytes thanks to dingledooper!!!

```
s;f(char*t){s=atoi(t)*60+atoi(t+3);s=s<6e3?s:6e3;}

```

Try it online!
> 9 votes

# Answer
# Python 3, ~~82~~ ~~72~~ ~~62~~ ~~61~~ 57 bytes

```
def f(s):x,y=map(int,s.split(":"));return min(x*60+y,6e3)

```

Try it online!

* -10 bytes by using `min()`.
* -10 bytes from Arnauld!
* -1 byte from nope!
* -4 bytes from Chas Brown!
> 8 votes

# Answer
# , 21 19 bytes

```
6e3<.60#.[:".' '2}]

```

Try it online!

* `[:".' '2}]` Convert the `:` to a space, then evaluate the string as a list of numbers.
* `60#.` Interpret result in base 60.
* `6e3<.` Minimum of that and 6000.
> 8 votes

# Answer
# perl -MList::Util=min -plF: -E, 25 bytes

```
$_=min 60*$F[0]+$F[1],6E3

```

Try it online!
> 8 votes

# Answer
## Batch, 55 bytes

```
@set/ps=
@cmd/cset/a"(s=%s::=*60+%)+(s-=6000)*(-s>>13)

```

Takes input on STDIN. Explanation: `%s::=*60+%` substitutes `*60+` for the `:` in the input, resulting in an arithmetic expression that converts the time into seconds. Since Batch has no minimum function, I then have to compute this via right-shifting the the difference which results in `0` or `-1` which is then used to adjust the seconds, which are then automatically output thanks to the use of `cmd/c`.
> 7 votes

# Answer
# Japt, 12 bytes

Feel like I'm missing a trick here ...

```
q': ì60 m6e3

```

Try it

```
q': ì60 m6e3     :Implicit input of string
q':              :Split on ":"
    ì60          :Convert to integer from base-60 digit array
        m6e3     :Minimum with 6000

```
> 6 votes

# Answer
# MathGolf, 14 bytes

```
2<i╟*l2>i+6♪*╓

```

Try it online.

**Explanation:**

```
                #  i.e. input = "99:80"
2<              # Take the first two characters of the (implicit) input-string
                #  STACK: ["99"]
  i             # Convert it from string to integer
                #  STACK: [99]
   ╟*           # Multiply it by 60
                #  STACK: [5940]
     l          # Push the input-string again
                #  STACK: [5940,"99:80"]
      2>i       # Leave its last two characters, and also cast it to an integer
                #  STACK: [5940,80]
         +      # Add them together
                #  STACK: [6020]
          6♪*   # Push 6*1000: 6000
                #  STACK: [6020,6000]
             ╓  # Only leave the smallest value of the top two values on the stack
                #  STACK: [6000]
                # (after which the entire stack joined together is output implicitly)

```
> 6 votes

# Answer
# Whitespace, 167 bytes

```
[S S S T    S T T   T   S T T   T   S S S S N
_Push_6000][S N
S _Duplicate_6000][S N
S _Duplicate_6000][S N
S _Duplicate_6000][T    N
T   S _Read_STDIN_as_char][T    T   T   _Retrieve][S S S T  T   S S S S N
_Push_48][T S S T   _Subtract][S S S T  S S T   S T T   S S S N
_Push_600][T    S S N
_Multiply][S N
S _Duplicate][S N
S _Duplicate][T N
T   S _Read_STDIN_as_character][T   T   T   _Retrieve][S S S T  T   S S S S N
_Push_48][T S S T   _Subtract][S S S T  T   T   T   S S N
_Push_60][T S S N
_Multiply][T    S S S _Add][S N
S _Duplicate][T N
T   S _Read_STDIN_as_character][S N
S _Duplicate][S N
S _Duplicate][T N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve][T    S S S _Add][S N
T   _Swap_top_two][T    S S T   _Subtract][S N
S _Duplicate][N
T   T   N
_If_negative_jump_to_Label_PRINT][S N
S _Duplicate][T S S T   _Subtract][N
S S N
_Create_Label_PRINT][T  S S S _Add][T   N
S T _Print_as_integer]

```

Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

**Explanation in pseudo-code:**

Unfortunately Whitespace is unable to read an integer when there is anything other than a newline (or nothing) behind it. Because of this, the minute-digits has to be read loose as characters, and seconds can be read as an integer..

```
Integer m1 = Read STDIN as character
m1 = m1 - 48
m1 = m1 * 600
Integer m2 = Read STDIN as character
m2 = m2 - 48
m2 = m2 * 60
Integer m = m1 + m2
Read STDIN as character (the ':', which we simply ignore)
Integer s = Read STDIN as integer
Integer total_seconds = m + s
If(total_seconds - 6000 < 0):
  Print total_seconds as integer to STDOUT
Else:
  Print 6000 as integer to STDOUT

```
> 6 votes

# Answer
# Befunge-93, 35 bytes

```
&~$"<"*&+:v
v!`*"<""d"<
_"d""<"*.@.

```

Try it online!

Reads a number, read a character (`:`) and discard it, multiply the read number with 60 (ASCII character 60 equals `"<"`), read the second number, and add it to the product (this gives the number of seconds). Dub the number of seconds; push 6000 (`6000 = 60 * 100 = "<" * "d"`) on the stack and compare. If 6000 is less than the number of seconds, push another 6000 on the stack and print it. Else, print the number of seconds (which is now the top of the stack).
> 4 votes

# Answer
# Jelly, 10 bytes

```
ṣ”:Vḅ60«6ȷ

```

A monadic Link accepting a list of characters which yields an integer.

**Try it online!**

### How?

```
ṣ”:Vḅ60«6ȷ - Link: list of characters, T
 ”:        - character ':'
ṣ          - split T at ':'
   V       - evaluate as Jelly code -> [m,s]
     60    - sixty
    ḅ      - convert from base -> 60*m+s
        6ȷ - 6*10^3 = 6000
       «   - minimum

```
> 4 votes

# Answer
# C++ (gcc), 92 bytes

```
#import<iostream>
main(){int m,s;char x;std::cin>>m>>x>>s;std::cout<<std::min(m*60+s,6000);}

```

Try it online!

Special Thanks to math junkie.

Special Thanks to ceilingcat for the educative suggestion.
> 4 votes

# Answer
# Ruby, 41 bytes

```
->i{[i[0,2].to_i*60+i[3,2].to_i,6e3].min}

```

Try it online!

16 bytes saved thanks to math-junkie
> 4 votes

# Answer
# x86-16 machine code, 30 bytes

Binary:

```
00000000: 33d2 e806 00b2 3cf6 e292 acad 2d30 3086  3.....<.....-00.
00000010: c4d5 0a03 c2ba 7017 3bc2 7e01 92c3       ......p.;.~...

```

Listing:

```
33 D2           XOR  DX, DX         ; zero DX
E8 0006         CALL CONV           ; get minutes into AX
B2 3C           MOV  DL, 60         ; multiplier 60 sec/min
F6 E2           MUL  DL             ; AX = AL * 60
92              XCHG AX, DX         ; save seconds in DX
AC              LODSB               ; skip ':' char
            CONV:
AD              LODSW               ; load next two ASCII chars into AX
2D 3030         SUB  AX, '00'       ; ASCII convert
86 C4           XCHG AL, AH         ; endian convert
D5 0A           AAD                 ; BCD to byte convert
03 C2           ADD  AX, DX         ; add minutes to seconds
BA 1770         MOV  DX, 6000       ; set up max comparison
3B C2           CMP  AX, DX         ; is result > 6000?
7E 01           JLE  DONE           ; if not, return current value
92              XCHG AX, DX         ; otherwise 6000
            DONE:
C3              RET                 ; return to caller

```

Input string in `[SI]`, output number of seconds in `AX`.

Sample I/O using test program:
> 4 votes

# Answer
# Charcoal, 13 bytes

```
Ｉ⌊⟦↨Ｉ⪪Ｓ:⁶⁰×⁶φ

```

Try it online! Link is to verbose version of code. Explanation:

```
      Ｓ         Input string
     ⪪ :        Split on literal `:`
    Ｉ           Cast each part to integer
   ↨    ⁶⁰      Convert from base 60
           ⁶    Literal 6
          ×     Multiplied by
            φ   Predefined variable 1000
 ⌊⟦             Take the minimum
Ｉ               Cast to string
                Implicitly print

```
> 3 votes

# Answer
# 05AB1E, 11 bytes

```
':¡60β6₄*)W

```

Try it online!

Coincidental port of most answers.

## Explained

```
':¡60β6₄*)W

min(lhs: base10(number: split(string: input, character: ":"), from: 60), rhs: times(lhs: 6, rhs: 1000))

':  | Push the character ":"
¡   | Split the input upon ":"s -> [mins, seconds]
60β | Convert the list from base 60 to base 10
6₄* | Push the number `6000`
)W  | Wrap the converted input and 6000 into a list and find the smallest.

```
> 3 votes

# Answer
# Perl 5 with `-plF/((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((\d+)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))):(\d+)/ -MList::Util+sum,min`, 16 bytes

Not competing with @Abigail's answer which is not 'cheaty' like this one.

```
$_=min 6e3,sum@F

```

Try it online!

### Explanation

Using the `-F` flag, the left part of the input is replicated 60 times and the right part is extracted once, into `@F`. These are `sum`med to yield the number of seconds and we use `min` to ensure it's not over 6000.
> 3 votes

# Answer
## Tcl, 54 bytes

```
proc f {a} {scan $a %d:%d a b
expr min(60*$a+$b,6000)}

```

Try it online!

## Explanation

Sadly, the times with leading zeroes mess up string interpolation directly into expr (using ternaries) because Tcl thinks they are octal, so I had to settle for using scan to force interpretation as decimal. Also, if `6000.0` is allowed as output, I can save 1 byte.
> 3 votes

# Answer
# K (ngn/k), 14 bytes

**Solution:**

```
6000&60/.'":"\

```

Try it online!

**Explanation:**

```
6000&60/.'":"\ / the solution
          ":"\ / split string on ":"
        .'     / value (convert "12" => 12)
     60/       / from base-60
6000&          / min of result and 6000

```
> 3 votes

# Answer
# Rust, 82 bytes

```
|s:&str|6000.min(60*s[..2].parse::<u32>().unwrap()+s[3..].parse::<u32>().unwrap())

```

Try it online!

Unfortunately type inference for parse is very restricted and the turbofish must be used every time.

I also made some versions using `fold` instead of parse, but they are longer:

With a tuple accumulator and a closure to combine minutes and seconds:

```
|s:&[u8]|6000.min((|(a,b)|60*a+b)(s.iter().fold((0,0),|(a,b),x|match x{58=>(b,0),_=>(a,10*b+*x as i32-48)})))

```

Using a \[i32;2\] accumulator and `.iter().sum()`

```
|s:&[u8]|6000.min(s.iter().fold([0,0],|[a,b],x|match x{58=>[60*b,0],_=>[a,10*b+*x as i32-48]}).iter().sum())

```

And then there's this ungodly abomination using `std::ops::Range<i32>` as an accumulator, with `-60*minutes` as the start and `seconds` as the end. Eww.

```
|s:&[u8]|6000.min(s.iter().fold(0..0,|a,x|match x{58=>-60*a.end..0,_=>a.start..10*a.end+*x as i32-48}).len())

```
> 3 votes

# Answer
# APL+WIN, 20 bytes

Prompts for time as string:

```
6E3⌊60⊥(⍎2↑n),⍎3↓n←⎕

```

Try it online! Courtesy of Dyalog Classic
> 2 votes

# Answer
# Burlesque, 19 bytes

```
ps1RAp^60.*.+6000<.

```

Try it online!

Explanation:

```
ps                  # Parses input string as block: mm:ss => { mm ":" ss }
  1RA               # Removes element at index 1 from block: { mm ss }
     p^             # Splits block to stack
       60.*         # Multiply top element by 60
           .+       # Sum both elements
             6000<. # Return the minimum of the calculated value or 6000

```
> 2 votes

# Answer
# Husk, 13 bytes

```
y6000B60mrx":

```

Try it online!

## Explanation

```
          x":    Split on colons
        mr       Convert from string form
     B60         Interpret in base 60
y6000            Minimum with 6000

```
> 2 votes

# Answer
# Java (JDK), 67 bytes

```
t->Math.min(6e3,new Long((t=t[0].split(":"))[0])*60+new Long(t[1]))

```

Try it online!

## Credits

* -4 bytes thanks to Kevin Cruijssen by changing the input type to an array of Strings.
> 2 votes

# Answer
# CJam, 17 bytes

```
q':/:i~\60*+6e3e<

```

Try it online!

```
q':/:i~\60*+6e3e<  e# Whole program
q                  e# Read input          [e.g "99:98"]
 ':/               e# Split on :          [e.g ["99" "98"]]
    :i             e# Convert to integers [e.g [99 98]]
      ~\           e# Dump and swap       [e.g 98 99]
        60*        e# Multiply by 60      [e.g 98 5940]
           +       e# Add                 [e.g 6038]
            6e3e<  e# Get minimum to 6000 [e.g 6000]
                   e# Implicit output

```
> 2 votes

# Answer
# Befunge-93 (FBBI), 25 bytes

```
"<|`*"<d":+&*&
@.<
*"<d@.

```

Try it online!

### Explanation:

The program consists of three parts (lines), the first one processes the input:

```
"<|`*"<d":+&*&    Stack                              IP direction

                  empty                              east
"<|`*"          push everything between the two quotes
                  42, 96, 124, 60                    east
      <         turn west
                  42, 96, 124, 60                    west
"<|`*"          push everything between the two quotes
                  60, 124, 96, 42, 42, 96, 124, 60   west
            *&  take an integer (minutes), convert to seconds
                  60*m, 124, ...                     west
          +&    take the next int, add to the total
                  60*m+s, 124, ...                   west
         :      duplicate TOS
                  60*m+s, 60*m+s, ...                west
    *"<d"       push 60*100 = 1000
                  6000, 60*m+s, 60*m+s, ...          west
   `            is greater than?
                  6000 > 60*m+s, 60*m+s, ...         west
  |             north-south if
                  60*m+s, ...                        north / south

```

If the total number of seconds is smaller or equal to 6000, the IP moves south and enters the second line:

```
@.<               Stack                              IP direction

                  60*m+s, ...                        south
  <             turn west
                  60*m+s, ...                        west
 .              print integer
                  124, ...                           west
@               Stop

```

If the number of second is greater than 6000, the IP moves north and enters the last line:

```
*"<d@.            Stack                              IP direction

                  60*m+s, ...                        north
  <             turn west
                  60*m+s, ...                        west
*"              push everything up to the next quote ...
 "<d@.          ... which is actually the same one.
                  60, 100, 64, ...                   west
*               Stop
                  6000, 64, ...                      west
     .          print 6000
                  64, ...                            west
    @           Stop

```
> 2 votes

# Answer
# Pyth, ~~16~~ 15 bytes

```
hS,6000ivcQ\:60

```

Try it online!

```
hS,6000ivcQ\:60   Implicit: Q=input()
         cQ\:     Split Q on ":"
        v         Convert each from string to integer
       i     60   Convert from base 60
  ,6000           Pair with 6000
 S                Sort
h                 Take the first element (i.e. smallest)
                  Implicit print

```

*Edit: Previous version:* `hS,6000isMcQ\:60`
> 2 votes

# Answer
# Julia ~~54~~ ~~53~~ 52 bytes

```
f(x)=((i,j)=parse.(Int,split(x,":"));min(60i+j,6e3))

```

try it online

A single line solution for Julia.

A couple neat tricks here, we use `f(x)=`, a generic function declaration so we don't have to use the `return` `end` or `function` keywords.

We then use a compound expression like this `(code;code;...)`.

Unfortunately, when using tuple destructuring `i,j=`, the tuple here must be wrapped in parenthesis for some reason, which adds two bytes.

Edits:

* 1 byte improvement using `60i` instead of `60*i`
* 1 byte improvement by removing trailing whitespace
> 2 votes

# Answer
# PowerShell, ~~50~~ 48 bytes

-2 bytes thanks to mazzy

```
$a,$b=$args-split':'
[Math]::min((60*$a+$b),6e3)

```

Try it online!
> 2 votes

# Answer
**C# (.NET Core) 77 bytes**

```
s=>Math.Min(60*int.Parse(s.Substring(0,2))+int.Parse(s.Substring(3,2)),6000);

```

It assumes that the position of the colon is always 3

Try it online
> 2 votes

# Answer
# C# (.NET Core), 76 bytes

```
s=>Math.Min(s.Split(':').Select(int.Parse).Aggregate((e,i)=>(e*60+i)),6000);

```

Try it online
> 2 votes

# Answer
# Scala, ~~66~~ 61 bytes

For those who like to live dangerously and assume things beyond a method's contract...

```
io.StdIn.readLine split ":"map(_.toInt)reduce(_*60+_)min 6000

```

`reduce` is not guaranteed to work from left to right, but it seems to do so by default.

Try it in Scastie
> 2 votes

# Answer
# V (vim), 18 bytes

```
f:i*60<Esc>lr+0C<c-r>=<c-r>"
<Esc>

```

Try it online!
> 2 votes

# Answer
# Io, 52 bytes

Port of the Python answer.

```
method(x,doString(x split(":")join("*60+"))min(6e3))

```

Try it online!
> 1 votes

# Answer
# , 46 bytes

```
`:`=c;min(6e3,eval(parse(t=scan(,"")))%*%60:1)

```

Try it online!

Just redefine `:` so that we can just use `eval` to concatenate the hours and minutes together, and do a dot product with `c(60,1)` to get the seconds.
> 1 votes

# Answer
# Dart, 88 bytes

```
import'dart:math';f(s)=>s.split(":").map(int.parse).reduce((v,e)=>min<num>(v*60+e,6e3));

```

Try it online!
> 1 votes

# Answer
The types and the `unwrap` make this longer than it could be otherwise.

# Rust, 121 bytes

```
use std::cmp::min;fn f(s:&str)->i32{let x:i32=s[..2].parse().unwrap();let y:i32=s[3..].parse().unwrap();min(x*60+y,6000)}

```

Try it online!

Explanation: `6000` had to be used because `6e3` is considered a float. `6e3 as i32` is longer than simply using `6000`. In production code I would have written it `6_000` but saving the character is the game.

`min` is not imported by default. So we have to pay for that import.

`parse` does the work of other languages type casting. But since it could fail we also need the unwrap. String to int conversions are costly in golf for Rust. Using `?` operator could in theory save us the `unwrap` but then the type for the return needs to be much longer: `Result<i32, std::num::ParseError>`. That also means the `collect` has to know about the `Result` too. We also have to wrap the final return in `Ok()`. So not much gain there.

I looked at using `split` but it ends up being longer due to working to get the tuple back out of the resulting iterator.
> 1 votes

# Answer
# Julia, 71 bytes

```
 function f(x)
        m,s=parse.(Int,split(x,":"))
        return min(m*60+s,6e3)
 end

```

Try it online!

The part which was most interesting to me here, is the parse.() which parses each element in the array. Note the dot operator before the parentheses.

Could have knocked off one more byte by putting show() in the function instead of return. But, the footer or output box, on tio, wind up a bit of a mess due to the lack of new lines from show.

```
 function f(x)
        m,s=parse.(Int,split(x,":"))
        show(min(m*60+s,6e3))
 end

```
> 1 votes

# Answer
# Python 3.8 (pre-release), 56 bytes

```
lambda x:min(int((k:=x.split(":"))[1])+60*int(k[0]),6e3)

```

Try it online!
> 1 votes

# Answer
# Golfscript, 28 bytes

```
":"/~~\~60*+.6000.@<{\}{}if;

```

Try it online!
> 1 votes

# Answer
# C# (.NET Core) ~~88~~ 87 bytes

```
s=>{var x=s.Split(':').Select(int.Parse).ToList();return Math.Min(60*x[0]+x[1],6000);};

```

Try it online

Removed trailing newline for 1 byte saving
> 1 votes

# Answer
# JavaScript (V8), 47 bytes

```
i=>Math.min(6e3,(i[0]+i[1]-0)*60+(i[3]+i[4]-0))

```

Call the function with the input string
> 1 votes

# Answer
# Go 1.21+, ~~93~~ 92 bytes

```
import."fmt"
func f(t string)int{var m,s int
Sscanf(t,"%d:%d",&m,&s)
return min(6e3,m*60+s)}

```

Attempt This Online!

Uses the brand new builtin `min` function to save 13 bytes.

# Go 1.20.x, ~~106~~ 104 bytes

```
import."fmt"
func f(t string)int{var m,s int
Sscanf(t,"%d:%d",&m,&s)
o:=m*60+s
if o>6e3{o=6e3}
return o}

```

Attempt This Online!
> 1 votes

# Answer
# ARBLE, 31 bytes

```
min(6e3,sub(s,1,2)*60+sub(s,4))

```

Try it online!
> 1 votes

# Answer
# AWK, 30 bytes (27 bytes + 3 penalty for -F:)

```
$0=6000<(a=$1*60+$2)?6000:a

```

Try it online!

Pretty straightforward one... Relies on `-F:` to shorten the code needed to access mins/secs components of the input.

```
         a=$1*60+$2          - temp variable w/ simple calc of time
$0=6000<(          )?6000:a  - ternary to cap limit at 6000

```
> 1 votes

# Answer
# Thunno 2, 10 bytes

```
':/60ḋ«ç⁷Ọ

```

Try it online!

#### Explanation

```
':/60ḋ«ç⁷Ọ  '# Implicit input
':/         '# Split it on ":"
   60ḋ       # Convert from base 60
      «ç⁷    # Push 6000
         Ọ   # Dyadic minimum
             # Implicit output

```
> 0 votes

# Answer
# Python, 95 Bytes

```
lambda i: f"Lower"if(int(i[0:2])*60)+int(int(i[3:5]))>6000else(int(i[0:2])*60)+int(int(i[3:5]))

```

Example Input:

```
76:92 # String input

```

Example Output:

```
4652 # Number of seconds

```

*Note: You do have to call the function and print it separately*

Try it online!
> 0 votes

# Answer
# Pure Bash, 35 bytes

```
echo $[s=${1/:/*60+},s>6000?6000:s]

```

Try it online!

# Pure Bash, 36 bytes

```
echo $[(r=${1/:/*60+})>(b=6000)?b:r]

```

Try it online!
> 0 votes

# Answer
# Itr, 15 bytes

`ê©àé2+à©·+6000m`

online interpreter

## Explanation

```
ê©àé2+à©·+6000m ; implicit input
ê               ; split input into two parts '##:' and '##'
 ©              ; evaluate the second part to get the number of seconds
  à             ; swap
   é            ; split of the last character ':'
    2+          ; add 2 to ':' (ascii 58) giving 60
      à         ; swap
       ©        ; evaluate the number of minutes
        ·       ; multiply minutes by 60
         +      ; add seconds
          6000  ; literal 6000
              m ; minimum
                ; implicit output

```
> 0 votes

# Answer
# Desmos, 43 bytes

Takes input in the form of a ASCII code array. Use this to convert testcases to ASCII codes.

```
f(S)=min(total([600,60,0,10,1](S-48)),6000)

```

Try it on Desmos!
> 0 votes

# Answer
# YASEPL, 43 bytes

```
=s=1'±colon!¥0,1*60=m¥1,1!+m}2,6000$6000`1<

```

explanation:

```
=s=1'±colon!¥0,1*60=m¥1,1!+m}2,6000$6000`1<           packed
=s                                                    set total time in seconds (S)
  =1'                                                 get user input and set it to var1
     ±colon                                           split it by ":"
           !¥0,1*60                                   set S to var1[0] (minutes) and multiply it by 60
                   =m¥1,1!+m                          set M to var1[1] (seconds) and add it to S
                            }2,6000$6000`1            if S > 6000, set it to 6000
                                          <           print S once done

```
> 0 votes

# Answer
# Swift, ~~63~~ 57 bytes

```
{min(Int(($0+"").prefix(2))!*60+Int($0.suffix(2))!,6000)}

```

Assign this closure to something and call it with the time in `"##:##"` format (or just call it directly).

> Since a Swift `String` can't be indexed using an `Int` (blame Unicode support, though you'd be surprised just how rare `String` indexing is in well-written, real-life code), I had to use the `prefix(_:)` and `suffix(_:)` methods instead.
> 0 votes

# Answer
# PARI/GP, 59 bytes

```
f(x)={s=strsplit(x,":");min(60*eval(s[1])+eval(s[2]),6000)}

```

Attempt This Online!
> 0 votes

# Answer
# Nibbles, 15 nibbles (7.5 bytes)

```
[6000+*60$;$

```

Attempt This Online!

## Explanation

```
      *60$   # multiply first part of input by 60
     +    ;$ # add second part of input
[6000        # return lesser of sum and 6000

```
> 0 votes

---
Tags: code-golf, math
---


title: Increment base-36 strings

text:
# Question
Title: Increment base-36 strings
This is a code golf version of a similar question I asked on stack earlier but thought it'd be an interesting puzzle.

Given a string of length 10 which represents a base 36 number, increment it by one and return the resulting string.

This means the strings will only contain digits from `0` to `9` and letters from `a` to `z`.

Base 36 works as follows:

The right most digit is incremented, first by using `0` to `9`

> # 0000000000 \> 9 iterations \> 0000000009

and after that `a` to `z` is used:

> # 000000000a \> 25 iterations \> 000000000z

If `z` needs to be incremented it loops back to zero and the digit to its left is incremented:

> # 000000010

### Further rules:

* You may use upper case or lower case letters.
* You may **not** drop leading zeros. Both input and output are strings of length 10.
* You do not need to handle `zzzzzzzzzz` as input.

### Test Cases:

```
"0000000000" -> "0000000001"
"0000000009" -> "000000000a"
"000000000z" -> "0000000010"
"123456zzzz" -> "1234570000"
"00codegolf" -> "00codegolg"

```

# Answer
# 05AB1E, 10 bytes

Input is in **uppercase**.

### Code

```
1ì36ö>36B¦

```

### Explanation

```
1ì           # Prepend a 1 to the number
  36ö        # Convert from base 36 to decimal
     >       # Increment by 1
      36B    # Convert from decimal to base 36
         ¦   # Remove the first character

```

Uses the **05AB1E** encoding. Try it online! or Verify all test cases.
> 6 votes

# Answer
# JavaScript (ES6), 45 bytes

*Saved 4 bytes thanks to @O.O.Balance*

```
s=>(parseInt(1+s,36)+1).toString(36).slice(1)

```

Try it online!
> 9 votes

# Answer
# Japt, 13 bytes

```
n36 Ä s36 ù0A

```

Try it online! and Verify test cases

Takes input as a string

## Explanation

```
n36            converts input to base 36
    Ä           +1
      s36       to base 36 string
          ù0A   left-pad with 0 to length 10

```
> 8 votes

# Answer
# Haskell, 58 bytes

```
d=['0'..'9']
f s=snd(span(<s)$mapM(\_->d++['a'..'z'])d)!!1

```

Try it online!

A very brute-force strategy: generate all the length-10 base-36 strings in order, and find the one that comes after the input in the list. Take an enormous amount of time on strings far from the start of the list.

---

# Haskell, 60 bytes

```
q '9'='a'
q c=succ c
f(h:t)|any(<'z')t=h:f t|r<-'0'<$t=q h:r

```

Try it online!

Reads the string left to right until it reaches a character followed by a suffix of all z's, which may be empty. Increments that character, and replaces the z's with 0's.
> 8 votes

# Answer
# C (gcc), 50 48 bytes

An explicit carry flag wasn't necessary after restructuring the loop to end as soon as no carry would happen. The 9-\>A adjustment is performed during the loop check.

Thanks to ceilingcat for the suggestion.

```
f(char*s){for(s+=9;(*s+=*s-57?1:8)>90;*s--=48);}

```

Try it online!

---

## Original version: 71 57 bytes

This version uses a carry flag to propagate updates: I set it to truthy to begin the increment. The string is modified in-place and only accepts 0-9, A-Z. The tricky part was making sure that 9-\>A got handled correctly on carries.

Edit: I repurposed the input pointer as the carry flag.

```
f(s){for(char*t=s+9;s;)*t--+=(s=++*t>90)?-43:7*!(*t-58);}

```

Try it online!
> 7 votes

# Answer
# C, ~~82~~ ~~81~~ ~~53~~ 50 bytes

```
f(char*s){for(s+=10;*--s>89;)*s=48;*s+=*s-57?1:8;}

```

Directly modifies the input string; input and output is in upper case. Try it online here. Thanks to Arnauld for golfing 24 bytes and to ceilingcat for golfing 3 more bytes.

Ungolfed:

```
f(char *s) { // function taking a string argument
     for(s += 10; *--s > 89; ) // skip to the least significant digit, and step through the string until you hit something other than a 'Z' (90 is the ASCII code for 'Z') ...
         *s = 48; // ... replacing each digit with a zero (48 is the ASCII code for '0')
         *s += // the next digit has to be incremented:
         *s - 57 // if it's not a '9' (ASCII code 57) ...
         ? 1 // ... that is straightforward ...
         : 8; // ... otherwise it has to be replaced with an 'A' (ASCII code 65 = 57 + 8)
 }

```
> 6 votes

# Answer
# Stax, 7 bytes

```
ûæ≥╡►N▀

```

Run and debug it

Explanation:

```
|3^|3A|z Full program, implicit input
|3       Convert from base 36
  ^      Increment
   |3    Convert to base 36
     A|z Fill with "0" to length 10
         Implicit output

```
> 6 votes

# Answer
# Perl 6, ~~34 32~~ 30 bytes

*Thanks to nwellnhof for -2 bytes through the use of the `o` operator to combine functions*

```
{S/.//}o{base :36(1~$_)+1: 36}

```

Try it online!

Function that converts the argument to base 36, adds 1, converts back and then formats it. Now uses the same tactic as Adnan's answer to preserve the leading zeroes.
> 5 votes

# Answer
# Online Turing Machine Simulator, 745 bytes

```
init:0
accept:2
0,0
0,0,>
0,1
0,1,>
0,2
0,2,>
0,3
0,3,>
0,4
0,4,>
0,5
0,5,>
0,6
0,6,>
0,7
0,7,>
0,8
0,8,>
0,9
0,9,>
0,a
0,a,>
0,b
0,b,>
0,c
0,c,>
0,d
0,d,>
0,e
0,e,>
0,f
0,f,>
0,g
0,g,>
0,h
0,h,>
0,i
0,i,>
0,j
0,j,>
0,k
0,k,>
0,l
0,l,>
0,m
0,m,>
0,n
0,n,>
0,o
0,o,>
0,p
0,p,>
0,q
0,q,>
0,r
0,r,>
0,s
0,s,>
0,t
0,t,>
0,u
0,u,>
0,v
0,v,>
0,w
0,w,>
0,x
0,x,>
0,y
0,y,>
0,z
0,z,>
0,_
1,_,<
1,0
2,1,-
1,1
2,2,-
1,2
2,3,-
1,3
2,4,-
1,4
2,5,-
1,5
2,6,-
1,6
2,7,-
1,7
2,8,-
1,8
2,9,-
1,9
2,a,-
1,a
2,b,-
1,b
2,c,-
1,c
2,d,-
1,d
2,e,-
1,e
2,f,-
1,f
2,g,-
1,g
2,h,-
1,h
2,i,-
1,i
2,j,-
1,j
2,k,-
1,k
2,l,-
1,l
2,m,-
1,m
2,n,-
1,n
2,o,-
1,o
2,p,-
1,p
2,q,-
1,q
2,r,-
1,r
2,s,-
1,s
2,t,-
1,t
2,u,-
1,u
2,v,-
1,v
2,w,-
1,w
2,x,-
1,x
2,y,-
1,y
2,z,-
1,z
1,0,<

```

Online interpreter
> 5 votes

# Answer
# 6502 (NMOS\*) machine code routine, 26 bytes

```
A0 09 F3 FB B1 FB C9 5B 90 07 A9 30 91 FB 88 10 F1 C9 3A D0 04 A9 41 91 FB 60

```

\*) uses an "illegal" opcode `ISB`/`0xF3`, works on all original NMOS 6502 chips, not on later CMOS variants.

Expects a pointer to a 10-character string in `$fb`/`$fc` which is expected to be a base-36 number. Increments this number in-place.

Doesn't do anything sensible on invalid input (like e.g. a shorter string) -- handles `ZZZZZZZZZZ` "correctly" by accident ;)

### Commented disassembly

```
; function to increment base 36 number as 10 character string
;
; input:
;   $fb/$fc: address of string to increment
; clobbers:
;   A, Y
 .inc36:
A0 09       LDY #$09            ; start at last character
 .loop:
F3 FB       ISB ($FB),Y         ; increment character ("illegal" opcode)
B1 FB       LDA ($FB),Y         ; load incremented character
C9 5B       CMP #$5B            ; > 'z' ?
90 07       BCC .checkgap       ; no, check for gap between numbers and letters
A9 30       LDA #$30            ; load '0'
91 FB       STA ($FB),Y         ; and store in string
88          DEY                 ; previous position
10 F1       BPL .loop           ; and loop
 .checkgap:
C9 3A       CMP #$3A            ; == '9' + 1 ?
D0 04       BNE .done           ; done if not
A9 41       LDA #$41            ; load 'a'
91 FB       STA ($FB),Y         ; and store in string
 .done:
60          RTS

```

---

### Example C64 assembler program using the routine:

**Online demo**

**Code in ca65 syntax:**

```
.import inc36   ; link with routine above

.segment "BHDR" ; BASIC header
                .word   $0801           ; load address
                .word   $080b           ; pointer next BASIC line
                .word   2018            ; line number
                .byte   $9e             ; BASIC token "SYS"
                .byte   "2061",$0,$0,$0 ; 2061 ($080d) and terminating 0 bytes

.bss
b36str:         .res    11

.data
prompt:         .byte   "> ", $0

.code
                lda     #<prompt        ; display prompt
                ldy     #>prompt
                jsr     $ab1e

                lda     #<b36str        ; read string into buffer
                ldy     #>b36str
                ldx     #$b
                jsr     readline

                lda     #<b36str        ; address of array to $fb/fc
                sta     $fb
                lda     #>b36str
                sta     $fc
                jsr     inc36           ; call incrementing function

                lda     #<b36str        ; output result
                ldy     #>b36str
                jmp     $ab1e

; read a line of input from keyboard, terminate it with 0
; expects pointer to input buffer in A/Y, buffer length in X
.proc readline
                dex
                stx     $fb
                sta     $fc
                sty     $fd
                ldy     #$0
                sty     $cc             ; enable cursor blinking
                sty     $fe             ; temporary for loop variable
getkey:         jsr     $f142           ; get character from keyboard
                beq     getkey
                sta     $2              ; save to temporary
                and     #$7f
                cmp     #$20            ; check for control character
                bcs     checkout        ; no -> check buffer size
                cmp     #$d             ; was it enter/return?
                beq     prepout         ; -> normal flow
                cmp     #$14            ; was it backspace/delete?
                bne     getkey          ; if not, get next char
                lda     $fe             ; check current index
                beq     getkey          ; zero -> backspace not possible
                bne     prepout         ; skip checking buffer size for bs
checkout:       lda     $fe             ; buffer index
                cmp     $fb             ; check against buffer size
                beq     getkey          ; if it would overflow, loop again
prepout:        sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
output:         lda     $2              ; load character
                jsr     $e716           ;   and output
                ldx     $cf             ; check cursor phase
                beq     store           ; invisible -> to store
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and show
                ora     #$80            ;   cursor in
                sta     ($d1),y         ;   current row
                lda     $2              ; load character
store:          cli                     ; enable interrupts
                cmp     #$14            ; was it backspace/delete?
                beq     backspace       ; to backspace handling code
                cmp     #$d             ; was it enter/return?
                beq     done            ; then we're done.
                ldy     $fe             ; load buffer index
                sta     ($fc),y         ; store character in buffer
                iny                     ; advance buffer index
                sty     $fe
                bne     getkey          ; not zero -> ok
done:           lda     #$0             ; terminate string in buffer with zero
                ldy     $fe             ; get buffer index
                sta     ($fc),y         ; store terminator in buffer
                sei                     ; no interrupts
                ldy     $d3             ; get current screen column
                lda     ($d1),y         ; and clear
                and     #$7f            ;   cursor in
                sta     ($d1),y         ;   current row
                inc     $cc             ; disable cursor blinking
                cli                     ; enable interrupts
                rts                     ; return
backspace:      dec     $fe             ; decrement buffer index
                bcs     getkey          ; and get next key
.endproc

```
> 5 votes

# Answer
# MATL, 12 bytes

```
36ZAQ5M10&YA

```

Try it online!

```
           % Implicit input
36ZA       % convert from base 36 to decimal
Q          % increment by 1
5M         % bring the 36 back on stack (done this way to avoid needing space separator after this)
10         % = minimum length of output string
&YA        % convert back to base 36 with those arguments
           % Implicit output

```
> 4 votes

# Answer
# JavaScript (ES6), 89 bytes

This one is not nearly as byte-efficient as the other JavaScript entry, but I made this without noticing this rule:

> Given a string **of length 10**

So this isn't a serious entry - just for fun! It works with strings of general length, such as `0abc`, and prepends a `1` when the first digit is `z`, e.g. `zzz` -\> `1000`. Input must be lowercase.

```
s=>(l=s[s.length-1],r=s.slice(0,-1),l=='z'?f(r||'0')+0:r+(parseInt(l,36)+1).toString(36))

```

## Explanation

The expression `(A, B, C)` actually means "do A, then do B, then return C", which I make use of to declare some variables I reuse in the code. `s` stands for "string", `l` means "last", `r` means "rest".

```
/*1*/ s=>(
/*2*/   l=s[s.length-1],
/*3*/   r=s.slice(0,-1),
/*4*/   l=='z'
/*5*/     ? f(r||'0')+0
/*6*/     : r+(parseInt(l,36)+1).toString(36))

```

This is a recursive function. For a typical string like `aza`, it will just increment the last character (see line 6) - `azb`. But for a string that ends with `z`, like `h0gz`, it will run itself on everything up to the last character (the `z`) and substitute a `0` in place of it (see line 5) - `f(h0gz)` = `f(h0g) + 0` = `h0h0`.

The `||'0'` in line 5 is so that the function works when it's called on a 1-length string (i.e. the string `'z'`). Without it, `f('')` is called (since `'z'.slice(0, -1)` is `''`), which has undefined behavior (literally - try it yourself), and that's no good. The expected result of `f('z')` is `'10'`, which is what we get from `f('0') + 0`, so we use `||'0'`. (`||'0'` is particularly useful because it doesn't get in the way of the *usual* case - `r` being at least 1-length (`s` at least 2-length) - because strings are falsey only when they are 0-length.)

The method for incrementing a string is the same as used in the other JS entry: convert the base-36 "number" into an actual number, add 1, then convert it back to base-36. We don't need to worry about the `1` from incrementing 'z' (`'z'` -\> `'10'`), since we never actually increment 'z' (see line 4 and 6: the last character is only incremented if it is not 'z').

Also, we never risk discarding leading zeroes, because we don't ever actually manipulate more than a single character at a time - only ever the last character in the string. The rest of the characters are cleanly sliced off as you slice any string and prepended afterwords.
> 4 votes

# Answer
# Haskell, 63 bytes

```
r.f.r
f('9':r)='a':r
f('z':r)='0':f r
f(c:r)=succ c:r
r=reverse

```

Try it online! Reverses the string and checks the first character:

* A `9` is replaced by an `a`.
* A `z` is replaced by a `0` and recursively the next character is checked.
* All other characters are incremented using `succ`, the successor function which can be used on Chars because they are an instance of the Enum class.

Finally the resulting string is reversed again.
> 4 votes

# Answer
# brainfuck, 109 bytes

```
,[>>,]<+[++++<[<--->>-<-]-[<->>+<---]<[[-]>-------<]+>>[[+<+>]<<+[>+<------]>>]-[<+>-----]<++++<]<[<<]>>[.>>]

```

Try it online!
> 4 votes

# Answer
# Java 8, ~~90~~ ~~76~~ 56 bytes

```
s->Long.toString(Long.valueOf(1+s,36)+1,36).substring(1)

```

Accepts both upper-case and lower-case letters for input. Output is always in lower case.

Thanks to Okx for golfing 18 bytes.

Try it online here.

Ungolfed:

```
s -> // lambda taking a String argument and returning a String
    Long.toString(Long.valueOf(1+s,36)+1,36) // prefix input with '1' to ensure leading zeros, convert to Long using base 36, increment, then convert back to String in base 36
    .substring(1) // remove the leading '1'

```
> 3 votes

# Answer
# PHP, ~~69~~ 64 bytes

**lame version**:

```
printf("%010s",base_convert(1+base_convert($argn,36,10),10,36));

```

Run as pipe with `-R`. Input case insensitive, output lowercase.

**first approach, 69 bytes:**

```
<?=str_pad(base_convert(1+base_convert($argn,36,10),10,36),10,'0',0);

```

Run as pipe with `-F`

**looping version, also 69 bytes**:

```
for($n=$argn;~$c=$n[$i-=1];)$f||$f=$n[$i]=$c!=9?$c>Y?0:++$c:A;echo$n;

```
* PHP 7.1 only: older PHP does not understand negative string indexes,
younger PHP will yield warnings for undefined constants.
* requires uppercase input. Replace `Y` and `A` with lowercase letters for lowercase input.

Run as pipe with `-nR`

... or try them online.
> 3 votes

# Answer
# Apl (Dyalog Unicode), 30 28 24 bytes

Thanks to ngn for the hint to save some bytes.

```
(f⍣¯1)1+f←36⊥1,(⎕D,⎕A)⍳⊢

```

Try it online!

* Requires ⎕IO of 0
* Uses upper case
> 3 votes

# Answer
# Charcoal, 14 bytes

```
×0⁹←⮌⍘⊕⍘Ｓ³⁶¦³⁶

```

Try it online! Link is to verbose version of code. Explanation:

```
×0⁹

```

Print 9 `0`s. This serves to pad the result.

```
←⮌⍘⊕⍘Ｓ³⁶¦³⁶

```

Convert the input from base 36, incremented it, then convert back to base 36. Then, reverse the result and print it leftwards.
> 3 votes

# Answer
# Retina 0.8.2, 12 bytes

```
T`zo`dl`.z*$

```

Try it online! Explanation: The `dl` part of the substitution destination expands to `0-9a-z` while the `o` copies that to the source, resulting in `z0-9a-z` (although the second `z` gets ignored as it can never match). This increments the matched digits. The `.z*$` part of the pattern matches the last non-`z` digit plus all trailing `z`s, thus handling the carry from their increment to `0`.
> 3 votes

# Answer
# Ruby, 40 bytes

```
->s{(s.to_i(36)+1).to_s(36).rjust 10,?0}

```

Try it online!

1. Convert the string to an integer interpreting it as base 36
2. Add 1
3. Convert back to base 36 string
4. Left pad with `0`s

`"zzzzzzzzzz"` returns an 11-long string
> 3 votes

# Answer
# Perl 5 \+ `-pl`, 31 bytes

Thanks to @DLosc for saving 3 bytes in the regex!

A different approach to @Xcali in their answer.

```
s/.z*$/$&=~y!0-9a-z!1-9a-z0!r/e
```

Try it online!

## Explanation

Replaces any character, followed by 0 or more `z`s, with the result of transliterating `0-9a-z` to `1-9a-z0`.
> 3 votes

# Answer
# Python 2, 88 bytes

```
def f(s):L,R=s[:-1],s[-1:];return s and[[L+chr(ord(R)+1),f(L)+'0'][R>'y'],L+'a'][R=='9']

```

Try it online!

Increments the string "by hand".
> 2 votes

# Answer
# Clean, ~~89~~ 84 bytes

```
import StdEnv
@['9':t]=['a':t]
@['z':t]=['0': @t]
@[c:t]=[inc c:t]
r=reverse

```

#

```
r o@o r

```

Try it online!

A shorter solution thanks to Laikoni.

# Clean, 115 bytes

I love it when I get to use `limit(iterate...`

```
import StdEnv
@'9'='a'
@c=inc c
?[h,'{':t]=[@h,'0': ?t]
?[h:t]=[h: ?t]
?e=e
$l=limit(iterate?(init l++[@(last l)]))

```

Try it online!

Produces the answer without converting bases using list matching.

* `? :: [Char] -> [Char]` performs forward carrying.
* `@ :: Char -> Char` increments by one, accounting for the gap between `'9'` and `'z'`.
* `$ :: [Char] -> [Char]` increments the last character and applies `?` until the value stabilizes.
> 2 votes

# Answer
# Wolfram Language (Mathematica), 39 bytes

```
IntegerString[#~FromDigits~36+1,36,10]&

```

Try it online!
> 2 votes

# Answer
# , ~~152~~ 123 bytes

```
function(x)f(utf8ToInt(x),10)
f=function(x,n,y=x[n]){x[n]=y+(y==57)*39+(y==122)*(-75)+1
"if"(y==122,f(x,n-1),intToUtf8(x))}

```

Try it online!

A completely different approach. Get the ASCII code points and recursively "increment" the right-most code point (making `0` (57) jump to to `a` (97) and `z` (122) go back to `0` (48)) until you run out of `z`s. Convert back to string.

### Old version

```
function(s,w=gsub("(z)(?=\\1*$)","0",s,,T),x=regexpr(".0*$",w)[1],y=substr(w,x,x),z=chartr("0-9a-z","1-9a-z0",y))sub(p(y,"(0*$)"),p(z,"\\1"),w)
p=paste0

```

Try it online!

This is all text manipulation, which is does not go hand-in-hand with R code golfing.

Replace all `z` at end of strings with `0`. Find location of last element before the newly minted trailing `0`s. Find the next base 36 digit. Make the change. Be glad to have barely beaten the Online Turing Machine Simulator solution.
> 2 votes

# Answer
# Zsh, ~~41~~ 36 bytes

```
echo ${(l:10::0:)$(([##36]36#$1+1))}

```

Try it online!
> 2 votes

# Answer
# Starry, 325 bytes

```
     + , , , , , , , , , ,     +      +   +   +`* +          + +* + +**      + * +* * '    +           + +* +* +* +*      +* `     +  + +                + +  *       +* *  '    +      +*           + +* +* +*  `   +   +           + +* +  *  **   +  + +'    +    +   ` +           + +* +  *    * .           + +* +  *   * +   '

```

Try it online!

# Explanation:

```
Put-a-zero-at-the-base-of-the-stack
|     +
Read-10-digits
| , , , , , , , , , ,
Initialise-next-stack
|     +
Initialise-carry-bit
|      +
|   +   +
Do
|`
    Top-of-stack:-[output-stack]-[carry-bit]-[next-value]
    Add-Carry-bit-to-digit
    |*

    Compare-with-58-("9"=57)
    | +
    5-double-triple-sub1-double
    |          + +* + +**      + * +*
    Take-difference
    | *
    If-one-above-"9"
    | '
        set-to-"a"=97=6-double-double-double-double-add1
        |    +
        |           + +* +* +* +*      +*
    | `

    Initialise-next-carry-bit
    |     +
    |  +

    Compare-with-123-("z"=122)
    | +
    11-squared-add2
    |                + +  *       +*
    Take-difference
    | *
    If-one-above-"z"
    |  '
        Delete-current-value
        |    +
        set-carry-bit
        |      +*
        Set-to-"0"=48
        |           + +* +* +*
    |  `

    Push-value-to-stack
    |   +   +
    |           + +* +  *
    |  **

    |   +  +
While-next-value-is-not-null
| +'

Pop-carry-bit-and-null-string-terminator
|    +    +
Do
|   `
    Get-top-value
    | +
    |           + +* +  *
    |    *

    Print-it
    | .

    Pop-the-value-off-the-stack
    |           + +* +  *
    |   *
While-stack-is-not-null
| +   '

```
> 2 votes

# Answer
# TypeScript’s type system, 145 bytes

```
type F<N>=N extends[...infer S,infer D]?"0123456789abcdedghijklmnopqrstuvwxyz"extends`${any}${D&string}${infer I}${any}`?[...S,I]:[...F<S>,"0"]:S

```

Try it at the TS playground

This is a generic type `F<N>` which takes a tuple type of characters and returns a type in the same format.

Explanation:

In the input tuple type `N`, match the last digit `D` and the rest `S`.

```
N extends[...infer S,infer D]

```

Match 0-9a-z against: anything + `D` \+ match the next character as `I` \+ anything.

```
"0123456789abcdedghijklmnopqrstuvwxyz"extends`${any}${D&string}${infer I}${any}`

```

If the match succeeded, return `S` \+ `I`.

```
?[...S,I]

```

Otherwise, recurse with S as the input, and append 0.

```
:[...F<S>,"0"]

```

This isn’t tail recursive, but that’s okay because the input is guaranteed to be 10 digits and the recursion limit for non tail-recursive TS types is 50.
> 2 votes

# Answer
# Ruby `-p`, ~~39~~ 36 bytes

Port of Dom Hastings’ Perl 5 answer; give them an upvote.

-3 bytes thanks to DLosc

```
sub(/.z*$/){$&.tr"0-9a-z","1-9a-z0"}

```

Attempt This Online!
> 2 votes

# Answer
# Python 3.6+ and gmpy2, 62 bytes

```
from gmpy2 import*;f=lambda s:f'{digits(mpz(s,36)+1,36):0>10}'

```

Try it online!

(Note that gmpy2 isn't part of Python standard library and requires separated installation)
> 1 votes

# Answer
# Pyke, 11 bytes

```
? b!!R+bhbt

```

Try it here!

```
? b         - Change default base of `base` command to 36
            -  This is kind of clever because it modifies the list of characters
            -  the command uses to exactly the same as it was originally, whilst
            -  forcing an overwrite from the default settings of 10.
            -  The default setup works for base 36, you just have to specify it
            -  time when using the command.
            -  Literally `b.contents = modify(b.contents, func=lambda: noop)`
   !!       - The previous command returns `0123456789abcdefghijklmnopqrstuvwxyz`
            -  So we convert it into a 1 with (not not ^) for the following command:
     R+     -     "1"+input
       b    -    base(^, 36)
        h   -   ^ + 1
         b  -  base(^, 36)
          t - ^[1:]

```

Could be 2 bytes shorter with the following language change: If hex mode is used, change all base\_36 and base\_10 usages to base\_92 (which isn't really base 92 in that context anyway)
> 1 votes

# Answer
# Perl 5 `-F`, 47 bytes

```
($_=/z/?0:/9/?a:++$_)&&last for reverse@F;say@F

```

Try it online!
> 1 votes

# Answer
# sed, 94 bytes

```
s/$/#:0123456789abcdefghijklmnopqrstuvwxyz#0/
:l
s/\(.\)#\(.*:.*\1\)\(#*.\)/\3\2\3/
tl
s/:.*//

```

Try it online!

Sed suffers a lot for having to change the characters by lookup.
> 1 votes

# Answer
# Powershell, ~~79~~ ~~78~~ 82 bytes

*+4 bytes: `z` and `9` inside an argument string fixed*

```
$i=1
"$args"[9..0]|%{$r=([char]($i+$_)+'0a')[2*($i*$_-eq57)+($i*=$_-eq'z')]+$r};$r

```

Less golfed test script:

```
$f = {

$i=1                    # increment = 1
"$args"[9..0]|%{        # for chars in positions 0..9 in the argument string (in reverse order)
    $c=[char]($i+$_)    # Important! A Powershell calculates from left to right
                        # Therefore the subexpression ($i+$_) gets a value before the subexpression ($i=$_-eq122)
    $j=2*($i*$_-eq57)+  # j = 2 if the current char is '9' and previous i is 1
        ($i*=$_-eq122)  # j = 1 if the current char is 'z' and previous i is 1
                        # j = 0 othewise
                        # side effect is: i = 1 if the current char is 'z' and previous i is 1, i = 0 othewise
    $c=($c+'0a')[$j]    # get element with index j from the array
    $r=$c+$r            # accumulate the result string
}
$r                      # push the result to a pipe

}

@(
    ,("09fizzbuzz" , "09fizzbv00")
    ,("0000000000" , "0000000001")
    ,("0000000009" , "000000000a")
    ,("000000000z" , "0000000010")
    ,("123456zzzz" , "1234570000")
    ,("00codegolf" , "00codegolg")
) | % {
    $s,$expected = $_
    $result = &$f $s
    "$($result-eq$expected): $result"
}

```

Output:

```
True: 09fizzBv00
True: 0000000001
True: 000000000a
True: 0000000010
True: 1234570000
True: 00codegolg

```
> 1 votes

# Answer
# C# (.NET Core), 125 bytes

```
a=>{var x="";for(int i=9;;i--){var y=a[i]==90?'0':a[i]==57?'A':(char)(a[i]+1);x=y+x;a=a.Remove(i);if(y>48)break;}return a+x;}

```

Try it online!

Ungolfed:

```
a => {
    var x = "";                 // initialize x
    for (int i = 9; ; i--)      // starting at 9 (length of string minus one) and decrementing i indefinitely
    {
        var y = a[i] == 90 ?        // if the last character of a is 'Z'
            '0' :                       // y = '0'
            a[i] == 57 ?                // if the last character of a is '9'
                'A':                        // y = 'A'
                (char)(a[i] + 1);           // y = the ascii value of last character plus 1
        x = y + x;                  // prepend y to x
        a = a.Remove(i);            // remove the last character of a
        if (y > 48)                 // if y is a character other than '0',
            break;                      // break from the loop
    }
    return a + x;               // return the remainder of a, with x appended
}

```
> 1 votes

# Answer
# Vyxal `r`, 61 bits<sup>v1</sup>, 7.625 bytes

```
36~β›R↳›

```

Try it Online!

TIL a) `36β` uses the alphabet `0-9a-z`, b) `β` is type aware and c)  pads one string to the length of another.

## Explained

```
36~β›R↳›
36~β      # Convert input from base 36, leaving the 36 on the stack
    ›     # Increment
     R    # and convert to base 36 using the alphabet `0-9A-Z`
      ↳   # pad left to length of input string
       ›  # and replace spaces with 0s

```
> 1 votes

# Answer
# Japt, 9 bytes

```
n36ÈÄÃùUA

```

Try it (includes all test cases)

```
n36ÈÄÃùTA     :Implicit input of string U
n36           :Convert from base 36
   È          :Pass through the following function and convert back
    Ä         :  Add 1
     Ã        :End function
      ùU      :Left pad with original U
        A     :  To length 10

```
> 1 votes

# Answer
# Uiua, ~~74 44 37 34~~ 32 characters

*-2 thanks to noodle man*

```
i←|1⊂⟨++1×39=@9.|@0i◌⟩=@z.°⊂
⍜⇌i

```

Try it here!

Give input by putting it after the code. The part `⍜⇌i` is basically indiscernible from a function in Uiua so I think this counts.

## Uiua, 74 characters

```
a←"0123456789abcdefghijklmnopqrstuvwxyz0"
i←|1⊂⟨∘|⊙i⟩=@0.⊡:a+1⊗:a⊢:↘1.
⍜⇌i

```

For this one, i didn't know you could add 1 to characters yet. Other changes were the discovery of `un join`, and using one switch and some math instead of three switches.
> 1 votes

# Answer
# Python 3.8 (pre-release), ~~96~~ ~~93~~ 84 bytes

*-9 bytes thanx to xnor*

```
lambda a:''.join(chr((n:=-~int(a,36)//36**i%36)+48+39*(n>9))for i in range(9,-1,-1))

```

Try it online!
> 1 votes

# Answer
# Jelly, 21 bytes

```
ØBḊiⱮḅ‘bɗ36Ż9¡ṫ-9‘ịØB

```

Try it online!

Uses uppercase. TIO link allows for lower/mixed case too.
> 0 votes

# Answer
# Elixir, 70 bytes

```
fn x->"1"<>x=Integer.to_string 1+String.to_integer("1"<>x,36),36;x end

```

Explanation:

Prepends `1` to the input, converts it to an integer in base 36, increments it, converts it to a string in base 36, and matches it to `"1" <> x` (reverse concatenation), then returns `x`.

Try it online!
> 0 votes

---
Tags: code-golf, string, base-conversion
---