Created
September 9, 2019 10:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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