Baseline: tree as shared
This commit is contained in:
commit
659c03bbf8
1471 files changed
+990535
No files matched your search
@@ -0,0 +1,19 @@
|
||||
# Generated by Programming+ from pseudo. Not reviewed for Mojo best practices.
|
||||
|
||||
# The position of the highest quality score; the first one, if several tie.
|
||||
def best_position(q: List[Int]) -> Int:
|
||||
# REQUIRE LENGTH(Q) >= 1
|
||||
# ENSURE 0 <= RESULT AND RESULT < LENGTH(Q)
|
||||
# ENSURE FORALL K IN [0, LENGTH(Q)) : Q[K] <= Q[RESULT]
|
||||
var best: Int
|
||||
best = 0
|
||||
# INVARIANT 0 <= Best AND Best < I
|
||||
# INVARIANT FORALL K IN [0, I) : Q[K] <= Q[Best]
|
||||
for i in range(1, len(q)):
|
||||
if q[i] > q[best]:
|
||||
best = i
|
||||
return best
|
||||
|
||||
|
||||
def main():
|
||||
print(best_position(List[Int](12, 30, 25, 30, 8)))
|
||||
Reference in new issue
Block a user