Skip to main content
8 of 11
edited body
Laikoni
  • 26.3k
  • 6
  • 52
  • 115

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

(incrementing 9 times)

0000000009

and after that a to z is used:

loop 25 times to 10

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"
Jack Hales
  • 359
  • 2
  • 10