Skip to content

Instantly share code, notes, and snippets.

@Wintus
Created November 22, 2024 16:14
Show Gist options
  • Save Wintus/4b1046e4a05f80aaae8fb9b0ccbe1eba to your computer and use it in GitHub Desktop.
Save Wintus/4b1046e4a05f80aaae8fb9b0ccbe1eba to your computer and use it in GitHub Desktop.
The bijective base-26 system
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