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

21 lines
689 B
Mojo

# origin: Programming+ exercise best-position
# status: unverified; `corpus.py verify` checks it on the pinned compiler
# probe: the position of the highest quality score; the first one, if several tie
# expect-stdout: 1
def best_position(q: List[Int]) -> Int:
# requires: len(q) >= 1
# ensures: 0 <= result < len(q)
# ensures: forall k in [0, len(q)) : q[k] <= q[result]
var best: Int = 0
for i in range(1, len(q)):
# invariant: 0 <= best < i
# invariant: forall k in [0, i) : q[k] <= q[best]
if q[i] > q[best]:
best = i
return best
def main():
var scores: List[Int] = [12, 30, 25, 30, 8]
print(best_position(scores))