Created
April 7, 2018 12:28
-
-
Save Voker57/7eaf8a4f0b5a9fa43d2434535ad53c79 to your computer and use it in GitHub Desktop.
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 int_to_pstoid(int) | |
int = int.to_i | |
result = "" | |
while int > 0 | |
result.prepend(((int % 27) + 'a'.ord - 1).chr) | |
int = int / 27 | |
end | |
result | |
end | |
def pstoid_to_int(postid) | |
result = 0 | |
chars = postid.chars.to_a.reverse | |
chars.each_index do |i| | |
result += (chars[i].ord - 'a'.ord + 1) * (27 ** i) | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment