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])) |
$ ruby damn-you-tim.rb 1000000000 | |
cfdgsxl |
This comment has been minimized.
This comment has been minimized.
I'm not gonna bother golfing that code, either |
This comment has been minimized.
This comment has been minimized.
this was not the intended result of my tweet - but a seriously good adventure in the minutiae of ruby |
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.