# 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"))