subtree(users/wpcarro): docking briefcase at '24f5a642'

git-subtree-dir: users/wpcarro
git-subtree-mainline: 464bbcb15c
git-subtree-split: 24f5a642af
Change-Id: I6105b3762b79126b3488359c95978cadb3efa789
This commit is contained in:
Vincent Ambo 2021-12-14 01:51:19 +03:00
commit 019f8fd211
766 changed files with 175420 additions and 0 deletions

View file

@ -0,0 +1,20 @@
from utils import get, init_table, print_table
def longest_common_substring(a, b):
"""
Computes the length of the longest string that's present in both `a` and
`b`.
"""
table = init_table(rows=len(b), cols=len(a), default=0)
for row in range(len(table)):
for col in range(len(table[row])):
if b[row] == a[col]:
table[row][col] = 1 + get(table, row - 1, col - 1)
return max([max(row) for row in table])
dictionary = ["fish", "vista"]
result = [longest_common_substring("hish", x) for x in dictionary]
expected = [3, 2]
print(result, expected)
assert result == expected
print("Success!")