Created
March 12, 2015 16:03
-
-
Save AlexArchive/85e77ddc0d3c2f028872 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
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()); | |
} | |
} |
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
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