This commit is contained in:
commit
568474d52f
1591 files changed
+528213
No files matched your search
@@ -0,0 +1,20 @@
|
||||
# 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))
|
||||
Reference in new issue
Block a user