Skip to content

Commit 74d03b4

Browse files
authored
35 (#239)
This PR solves problem 35.
1 parent 921b15d commit 74d03b4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

HumanEvalLean/HumanEval35.lean

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
11
module
22

3-
def max_element : Unit :=
4-
()
3+
/-! ## Implementation -/
4+
5+
def maxElement (xs : Array Int) : Int :=
6+
xs.max?.getD 0
7+
8+
/-! ## Tests -/
9+
10+
example : maxElement #[1, 2, 3] = 3 := by native_decide
11+
example : maxElement #[5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10] = 124 := by native_decide
12+
13+
/-! ## Verification -/
14+
15+
theorem maxElement_le_iff {xs : Array Int} {y : Int} (h : xs ≠ #[]) :
16+
maxElement xs ≤ y ↔ ∀ x ∈ xs, x ≤ y := by
17+
simp [maxElement, Array.max?_eq_some_max h, Array.max_le_iff]
18+
19+
theorem maxElement_mem {xs : Array Int} (h : xs ≠ #[]) :
20+
maxElement xs ∈ xs := by
21+
simpa [maxElement, Array.max?_eq_some_max h] using Array.max_mem h
522

623
/-!
724
## Prompt
@@ -40,4 +57,4 @@ def check(candidate):
4057
assert candidate([1, 2, 3]) == 3
4158
assert candidate([5, 3, -5, 2, -3, 3, 9, 0, 124, 1, -10]) == 124
4259
```
43-
-/
60+
-/

0 commit comments

Comments
 (0)