Files
pplus-core/mojo/local/match-reset.mojo
T
2026-10-05 03:03:38 +00:00

22 lines
687 B
Mojo

# origin: Programming+ exercise match-reset
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: matched is reset in the wrong place, so one mismatch poisons every later window
# expect-stdout: []
def match_pattern(p: String, t: String) -> List[Int]:
var n = t.count_codepoints()
var m = p.count_codepoints()
var answer = List[Int]()
var matched = True
for i in range(n - m + 1):
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("GC", "GATGCA"))