Created
February 11, 2015 16:51
-
-
Save lukealbao/42ab2618b8e95dea97f6 to your computer and use it in GitHub Desktop.
string => number
This file contains hidden or 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
def encode(text, decode=False): | |
"Credit for this strategy goes to http://stackoverflow.com/a/16872684" | |
table = {'a':2, 'b':3, 'c':5, 'd':7, 'e':11, 'f':13, 'g':17, 'h':19, | |
'i':23, 'j':29, 'k':31, 'l':37, 'm':41, 'n':43,'o':47, 'p':53, 'q':59, | |
'r':61, 's':67, 't':71, 'u':73, 'v':79, 'w':83, 'x':89, 'y':97, 'z':101} | |
if not decode: | |
return reduce(mul,[table[char] for char in text]) if text else '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment