Files
pplus-library/mojo/local/match.mojo
T
alexm 568474d52f
Test (in pplus-core) / in-core (push) Failing after 28m44s
Initial commit
2026-11-12 22:23:48 -05:00

22 lines
664 B
Mojo

# origin: Programming+ exercise match
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: every position where pattern p occurs exactly in text t
# expect-stdout: [1]
def match_pattern(p: String, t: String) -> List[Int]:
var n = t.count_codepoints()
var m = p.count_codepoints()
var answer = List[Int]()
for i in range(n - m + 1):
var matched = True
for j in range(m):
if t[codepoint=i + j] != p[codepoint=j]:
matched = False
break
if matched:
answer.append(i)
return answer^
def main():
print(match_pattern("ATT", "GATTACA"))