Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@TwP

This comment has been minimized.

Copy link

@TwP TwP commented Mar 8, 2012

:trollface:

@paul

This comment has been minimized.

Copy link
Owner Author

@paul paul commented Mar 8, 2012

I'm not gonna bother golfing that code, either

@TwP

This comment has been minimized.

Copy link

@TwP 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

This comment has been minimized.

Copy link

@cookrn 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