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

18 lines
584 B
Mojo

# origin: Programming+ exercise first-unknown
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: the position of the first N in t, or the length of t when there is none
# expect-stdout: 3
def first_unknown(t: String) -> Int:
# ensures: 0 <= result <= |t|
# ensures: forall k in [0, result) : t[k] != 'N'
var n: Int = t.count_codepoints()
var i: Int = 0
while i < n and String(t[codepoint=i]) != "N":
# invariant: forall k in [0, i) : t[k] != 'N'
i += 1
return i
def main():
print(first_unknown("GATNACA"))