Skip to content

Instantly share code, notes, and snippets.

@AlexArchive
Created March 12, 2015 16:03
Show Gist options
  • Save AlexArchive/85e77ddc0d3c2f028872 to your computer and use it in GitHub Desktop.
Save AlexArchive/85e77ddc0d3c2f028872 to your computer and use it in GitHub Desktop.
public static class IdentifierGenerator
{
private const string Alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
private static readonly int _base = Alphabet.Length;
public static string Encode(int index)
{
if (index == 0)
return Alphabet[0].ToString();
var encoded = string.Empty;
while (index > 0)
{
encoded += Alphabet[index % _base];
index = index / _base;
}
return string.Join(string.Empty, encoded.Reverse());
}
}
public class Program
{
private static void Main()
{
while (true)
{
string input = Console.ReadLine();
int id = int.Parse(input);
Console.WriteLine("http://easysha.re/{0}", IdentifierGenerator.Encode(id));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment