Skip to content

Commit b3128f8

Browse files
committed
64
1 parent 41b2490 commit b3128f8

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

HumanEvalLean/HumanEval64.lean

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,38 @@
11
module
2+
import Std
23

3-
def vowels_count : Unit :=
4-
()
4+
open Std
5+
6+
def vowelsList : List Char :=
7+
['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
8+
9+
def vowels : HashSet Char :=
10+
.ofList vowelsList
11+
12+
def vowelsCount (s : String) : Nat :=
13+
let nVowels := s.chars.filter (· ∈ vowels) |>.length
14+
let atEnd := if s.back?.any (fun c => c == 'y' || c == 'Y') then 1 else 0
15+
nVowels + atEnd
16+
17+
example : vowelsCount "abcde" = 2 := by native_decide
18+
example : vowelsCount "Alone" = 3 := by native_decide
19+
example : vowelsCount "key" = 2 := by native_decide
20+
example : vowelsCount "bye" = 1 := by native_decide
21+
example : vowelsCount "keY" = 2 := by native_decide
22+
example : vowelsCount "bYe" = 1 := by native_decide
23+
example : vowelsCount "ACEDY" = 3 := by native_decide
24+
25+
theorem String.back?_eq {s : String} : s.back? = s.toList.getLast? :=
26+
sorry -- https://github.com/leanprover/lean4/pull/13105
27+
28+
theorem vowelsCount_eq {s : String} :
29+
vowelsCount s = (s.toList.filter (· ∈ vowelsList)).length +
30+
(if s.toList.getLast? = some 'y' ∨ s.toList.getLast? = some 'Y' then 1 else 0) := by
31+
simp only [vowelsCount, ne_eq, ← Iter.length_toList_eq_length,
32+
Iter.toList_filter, String.toList_chars, ↓Char.isValue]
33+
simp only [vowels, HashSet.mem_ofList, List.contains_eq_mem, decide_eq_true_eq, ↓Char.isValue,
34+
Option.any_eq_true, Bool.or_eq_true, beq_iff_eq, Nat.add_left_cancel_iff]
35+
simp [and_comm, String.back?_eq]
536

637
/-!
738
## Prompt
@@ -54,4 +85,4 @@ def check(candidate):
5485
assert True, "This prints if this assert fails 2 (also good for debugging!)"
5586
5687
```
57-
-/
88+
-/

0 commit comments

Comments
 (0)