Created
March 8, 2012 23:18
-
-
Save paul/2004078 to your computer and use it in GitHub Desktop.
This file contains 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
LETTERS = "abcdefghijklmnopqrstuvwxyz".split('') | |
def base_alpha_26(int) | |
num = int | |
letters = [] | |
i = 0 | |
i += 1 until 26**i > int | |
while (i -= 1) >= 0; | |
letters << (num / 26**i) | |
num = num % (26**i) | |
end | |
letters.map { |l| LETTERS[l-1] }.join | |
end | |
puts base_alpha_26(Integer(ARGV[0])) |
This file contains 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
$ ruby damn-you-tim.rb 1000000000 | |
cfdgsxl |
this was not the intended result of my tweet - but a seriously good adventure in the minutiae of ruby
Just for good measure, golfed.
def base_alpha_26(i)
l,n,e,j=('a'..'z').to_a,i,[],0;j+=1 until 26**j>i;while(j-=1)>=0;e<<n/26**j;n%=26**j;end;e.map{|k|l[k-1]}*''
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not gonna bother golfing that code, either