Skip to content

Instantly share code, notes, and snippets.

@paul
Created March 8, 2012 23:18
Show Gist options
  • Save paul/2004078 to your computer and use it in GitHub Desktop.
Save paul/2004078 to your computer and use it in GitHub Desktop.
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
@paul
Copy link
Author

paul commented Mar 8, 2012

I'm not gonna bother golfing that code, either

@TwP
Copy link

TwP commented Mar 8, 2012

this was not the intended result of my tweet - but a seriously good adventure in the minutiae of ruby

@cookrn
Copy link

cookrn commented Mar 9, 2012

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