Skip to content

Instantly share code, notes, and snippets.

@GUIpsp
Created April 27, 2013 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GUIpsp/5472868 to your computer and use it in GitHub Desktop.
Save GUIpsp/5472868 to your computer and use it in GitHub Desktop.
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