Created
April 27, 2013 12:03
-
-
Save GUIpsp/5472868 to your computer and use it in GitHub Desktop.
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
import string | |
lowercase=" "+string.lowercase | |
def countPatterns(pattern, string): | |
rep=string.replace(pattern, "L") | |
return len(rep) | |
def handleOverflow(listt, current): | |
if listt[current] == len(lowercase)-1: | |
if len(listt) == current+1: | |
listt.append(1) | |
else: | |
listt[current+1]=listt[current+1]+1 | |
handleOverflow(listt,current+1) | |
listt[current]=0 | |
def encToChar(pattern, string): | |
current=[] | |
togo=countPatterns(pattern,string) | |
current.append(0) | |
while togo != 0: | |
togo=togo-1 | |
current[0]=current[0]+1 | |
handleOverflow(current,0) | |
return current | |
def decode(pattern,string): | |
chars=encToChar(pattern, string) | |
final="" | |
for i in chars: | |
final=final+lowercase[i] | |
return final | |
print decode("10","10"*(8+5*26+12*26**2+12*26**3+15*26**4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment