# I didn't write this.
def entry(x, y):
if len(x) < len(y):
return -1
if x.startswith(y):
return 0
return 1 + entry(x[1:], y)
# Or this.
def entry(x, y, old_entry=entry):
e = old_entry(x, y)
if e == len(x)-1:
return -1
return e
# I might have written this. But I didn't.
def entry(x, y, old_entry=entry):
e = old_entry(x, y)
if e == -1 and x[-1] == y[0]:
return len(x)-1
return e
# I didn't write this either.
def entry(x, y, old_entry=entry):
if x not in y:
return -1
return old_entry(x, y)
# Somebody else must have written this. It's not mine.
class ContainsFlip(str):
def __contains__(self, other):
return other in self
def entry(x, y, old_entry=entry):
return old_entry(ContainsFlip(x), ContainsFlip(y))
# This isn't it either. It isn't even good.
def entry(x, y, old_entry=entry):
try:
return old_entry(x, y)
except RecursionError:
g = [x[i:i+len(y)] for i in range(0, len(x), len(y))]
if y in g:
return g.index(y)
return -1
# I would never do this.
def entry(x, y, old_entry=entry):
s = ""
for i in range(len(x)):
s += x[i:i+len(y)]
return old_entry(s, y)
# Not in a million years.
import sys
def entry(x, y, old_entry=entry):
for c in range(0, sys.maxunicode+1):
c = chr(c)
if c not in x:
filler = c
break
return old_entry(x + filler*(len(y)-1), y)
# Appalling, indeed, but not in a "me" way.
def entry(x, y, old_entry=entry,
possible_next_indices = [0] ):
result = -1
for i, c in enumerate(x):
for j, index in enumerate(possible_next_indices):
if c == y[index]:
if possible_next_indices[j]+1 == len(y):
result = i-len(y)+1
break
else:
possible_next_indices[j] += 1
else:
possible_next_indices[j] = None
else:
possible_next_indices[:] = [x for x in possible_next_indices if x is not None]
possible_next_indices.append(0)
continue
break
return old_entry(" "*result + "x", "x")
# Who _knows_ who wrote this? Not me. I don't know who wrote it. Because it wasn't me.
old_entry = entry
def entry(x, y):
return not old_entry(x, y) and not x.startswith(y) and -1 or old_entry(x, y)
# Ah, I wrote this one.
import functools
def entry(x, y, _old_entry=entry):
global old_entry
old_entry = functools.lru_cache(old_entry)
return _old_entry(x, y)