Files
pplus-web/tests/snapshots/sync-mojo/match.mojo
T
2026-10-05 03:03:38 +00:00

28 lines
757 B
Mojo

# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
# 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 - m + 1):
# 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"))