17 lines
511 B
Mojo
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"))
|