Skip to content

Instantly share code, notes, and snippets.

@LevitatingBusinessMan
Created September 9, 2019 10:26
Show Gist options
  • Select an option

  • Save LevitatingBusinessMan/02355876df0bc00881ee15f11b43e8ae to your computer and use it in GitHub Desktop.

Select an option

Save LevitatingBusinessMan/02355876df0bc00881ee15f11b43e8ae to your computer and use it in GitHub Desktop.
Did a programming battle against a friend who could design this program the quickest
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
const maxLength = 10;
const indeces = [0];
while (indeces.length < maxLength) {
let string = ""
for (let i = 0; i < indeces.length; i++) {
string += chars[indeces[i]]
}
console.log(string);
let lastElementIndex = indeces.length - 1;
increase(lastElementIndex);
function increase (index) {
//Room to increase
if (indeces[index] < chars.length - 1)
indeces[index]++;
//No room to increase, increase element before last
else {
//overflow it
indeces[index] = 0;
//Already at start, add new character
if (index == 0)
indeces.unshift(0);
//Otherwise increase character before index
else increase(index-1)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment