Created
November 22, 2024 16:14
-
-
Save Wintus/4b1046e4a05f80aaae8fb9b0ccbe1eba to your computer and use it in GitHub Desktop.
The bijective base-26 system
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
| def naive(n) | |
| s = ?A | |
| (n-1).times { s.succ! } | |
| s | |
| end | |
| def digits(n, base=10) | |
| ds = [] | |
| while n > 0 | |
| case n.divmod(base) | |
| in [n, mod] | |
| ds << mod | |
| end | |
| end | |
| ds | |
| end | |
| AZ = [*?A..?Z].freeze | |
| def to_bb26(n) | |
| digits(n, 26).map { AZ[_1-1] }.reverse.join | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment