commit
401084bab3
265 files changed
+69224
No files matched your search
@@ -0,0 +1,27 @@
|
||||
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
||||
|
||||
# One bound is wrong. Every position where pattern P occurs exactly in text T.
|
||||
def match_(p: String, t: String) -> List[Int]:
|
||||
# Set up
|
||||
var n: Int
|
||||
var m: Int
|
||||
var matched: Bool
|
||||
var answer = List[Int]()
|
||||
n = t.count_codepoints()
|
||||
m = p.count_codepoints()
|
||||
# Visit each legal start
|
||||
for i in range(n):
|
||||
# Test: does the pattern match here?
|
||||
matched = True
|
||||
for j in range(m):
|
||||
if String(t[codepoint=i + j]) != String(p[codepoint=j]):
|
||||
matched = False
|
||||
break
|
||||
# Update
|
||||
if matched:
|
||||
answer.append(i)
|
||||
return answer.copy()
|
||||
|
||||
|
||||
def main():
|
||||
print(match_("ATT", "GATTACA"))
|
||||
Reference in new issue
Block a user