move OEIS solver to separate file + add reverse chapter and reverse word search

This commit is contained in:
relikd
2021-02-16 20:20:14 +01:00
parent d2e5ad9b86
commit 1ddc30cd27
3 changed files with 130 additions and 96 deletions

View File

@@ -151,18 +151,18 @@ class RuneText(object):
# return False
# return all(x.index == y.index for x, y in zip(self, other))
def enum_words(self): # [(start, end, len), ...] may include \n \r
def enum_words(self, reverse=False): # [(start, end, len), ...]
start = 0
r_pos = 0
word = []
for i, x in enumerate(self._data):
for i, x in enumerate(reversed(self._data) if reverse else self._data):
if x.kind == 'r':
r_pos += 1
word.append(x)
elif x.kind == 'l':
continue
else:
if len(word) > 0:
if len(word) > 0: # RuneText may include \n and \r
yield start, i, r_pos - len(word), RuneText(word)
word = []
start = i + 1