Skip to content

Instantly share code, notes, and snippets.

@ta1hia
Created July 10, 2016 23:01
Show Gist options
  • Save ta1hia/f5f34a21eeca7017fad52d5cb537916f to your computer and use it in GitHub Desktop.
Save ta1hia/f5f34a21eeca7017fad52d5cb537916f to your computer and use it in GitHub Desktop.
dropbox example q
def rebluebluered(s, pattern):
return search(s, pattern, dict())
def search(left, pattern, matches):
if (not pattern and left) or (pattern and not left):
return False
if not pattern and not left:
return True
pch = pattern[0]
if matches.get(pch):
word = matches[pch]
if left.find(word) == 0:
return search(left[len(word):], pattern[1:], matches)
else:
return False
word = ""
for i, c in enumerate(left):
word += c
matches[pch] = word
print(matches, left, pch)
if search(left[i+1:], pattern[1:], matches):
return True
matches.pop(pch)
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment