May 3, 2014 by Daniel P. Clark

Code Golf Challenge Unique Base 64 Incrementor

The goal is to write a script that will use your (Base 64) numbering system and never repeat any character within the string while incrementing.

When you rollover a big number that jumps to the next place value you need to substitute it with the next unique in place… example (in Base 10) 0985,0986,0987 jumps to 1023, 1024, 1025 to avoid repetition. Note: Rollovers are when you hit the top place value like 0999 and roll over to the next place value 1000

So increment all 12 character unique strings without wasting CPU cycles on skip loops.


  • No like characters within the 12 character string.
  • No skip/next command in loop from “0985”,”0986″,”0987″ to “1023” (Base 10 example), use substitution. This is a rollover. Rollovers are no skip zones.
  • All down counts of any length (starting from the highest value character towards the next +11 characters) get substituted on rollover Example: if Z was highest value character in the base and Y was next then YXWVUTSRQPON will roll over to Z0123456789a


Pass 5 test cases with different position rollover cases (when the next place position increments).

About Number Bases

Our numbering system is (Base 10). That includes 0-9. Binary is (Base 2), that’s only >1’s and 0’s. Hex is (Base 16) (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). A hexadecimal “F” has a >(Base 10) value of 15.

In Binary, a string of two binary characters can have only two unique states. Like ’10’ >and ’01’. In this challenge Binary is not a possible choice since you can’t have any more >unique amount of characters then two since you only have 1 and 0.

(Base 64) has 64 individual characters which would translate in value in (Base 10) from >between 0 to 63. See here for more on (Base 64)

Logic Insights

Your incrementor function will increment to the next ‘not in string’ character on the right end until it gets to the highest character. Once it get’s to the last character then it passes on to the swap task.

The swap task then looks for the chunk to jump to eg: in (Base 10) to go from 00987 to the next level would be 01234. So seeing 00987 is the set to replace we have the 0 which “can” be incremented, and then the 987 which is a counting down sequence 9, 8, 7. So we then increment the first number to the left so 0 turns to 1, and then substitute the 987 with the smallest unused numbers from left to right, which is 234.

Here is a working long answer written in Ruby:

The order of the (base 64) used in this code and output is as is defined on Wikipedia

And here is it’s output.


Please head over to github and fork and send a pull request and name your file as follows golfb64-<yourname>.xxx for your golf answers and  longb64-<yourname>.xxx for your long answer versions. Use any promming language you’d like. I’ve included my long version longb64-danielpclark.rb

To see other people’s submissions you can check here as well.

Please comment, share, subscribe to my RSS Feed,and follow me on twitter @6ftdan!

God Bless! – Daniel P. Clark

#base 64#challenge#code golf#programming
0 0 vote
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments