Skip to content

Instantly share code, notes, and snippets.

@prat0318
Created November 12, 2013 03:49
Show Gist options
  • Save prat0318/7425181 to your computer and use it in GitHub Desktop.
Save prat0318/7425181 to your computer and use it in GitHub Desktop.
encode strings A->1...Z->26 ...total combinations possible by reading input string
def encoding_ways(str):
if((len(str) == 1) or (len(str) == 0)): return 1
total1 = encoding_ways(str[1:])
if((str[0] == '1') or ((str[0] == '2') and (1 <= int(str[1])) and (int(str[1]) <= 6))):
total1 = total1 + encoding_ways(str[2:])
return total1
print encoding_ways('12')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment