Skip to content

Commit 3f1553c

Browse files
committed
Add solution for HumanEval3
1 parent c08d44f commit 3f1553c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

HumanEvalLean/HumanEval3.lean

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
1-
def below_zero : Unit :=
2-
()
1+
def belowZero (l : List Int) : Bool :=
2+
go 0 l
3+
where
4+
go (cur : Int) (remaining : List Int) : Bool :=
5+
if cur < 0 then
6+
true
7+
else
8+
match remaining with
9+
| [] => false
10+
| l::rem => go (cur + l) rem
11+
12+
theorem belowZero_iff {l : List Int} : belowZero l ↔ ∃ n, (l.take n).sum < 0 := by
13+
suffices ∀ c, belowZero.go c l ↔ ∃ n, c + (l.take n).sum < 0 by simpa using this 0
14+
intro c
15+
induction l generalizing c with
16+
| nil => simp [belowZero.go]
17+
| cons h t ih =>
18+
simp only [belowZero.go, Bool.if_true_left, Bool.or_eq_true, decide_eq_true_eq, ih]
19+
refine ⟨?_, ?_⟩
20+
· rintro (hc|⟨n, hn⟩)
21+
· exact ⟨0, by simpa⟩
22+
· exact ⟨n + 1, by simpa [← Int.add_assoc]⟩
23+
· rintro ⟨n, hn⟩
24+
rcases n with (_|n)
25+
· exact Or.inl (by simpa using hn)
26+
· exact Or.inr ⟨n, by simpa [Int.add_assoc] using hn⟩
327

428
/-!
529
## Prompt
@@ -51,4 +75,4 @@ def check(candidate):
5175
assert candidate([1, -1, 2, -2, 5, -5, 4, -5]) == True
5276
assert candidate([1, -2, 2, -2, 5, -5, 4, -4]) == True
5377
```
54-
-/
78+
-/

0 commit comments

Comments
 (0)