Files
pplus-core/tests/snapshots/sync-mojo/first-unknown.mojo
T
2026-10-05 03:03:38 +00:00

17 lines
511 B
Mojo

# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
# The position of the first N in T, or LENGTH(T) when there is none.
def first_unknown(t: String) -> Int:
# ENSURE 0 <= RESULT AND RESULT <= LENGTH(T)
# ENSURE FORALL K IN [0, RESULT) : T[K] != 'N'
var i: Int
i = 0
# INVARIANT FORALL K IN [0, I) : T[K] != 'N'
while i < t.count_codepoints() and String(t[codepoint=i]) != "N":
i = i + 1
return i
def main():
print(first_unknown("GATNACA"))