-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHumanEval51.lean
More file actions
95 lines (72 loc) · 2.57 KB
/
HumanEval51.lean
File metadata and controls
95 lines (72 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
def IsSubseq (s₁ : String) (s₂ : String) : Prop :=
List.Sublist s₁.toList s₂.toList
def vowels : List Char := ['a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U']
def NoVowels (s : String) : Prop :=
List.all s.toList (· ∉ vowels)
def MaximalFor [LE α] (P : ι → Prop) (f : ι → α) (x : ι) : Prop :=
-- Same as MaximalFor in Mathlib
P x ∧ ∀ y : ι, P y → f x ≤ f y → f y ≤ f x
def RemoveVowelsIff (solution : String → String) : Prop :=
(s x : String) → (solution s = x) → MaximalFor (fun i => NoVowels i ∧ IsSubseq i s) (String.length) x
def removeVowels (s : String) : String :=
String.ofList (s.toList.filter (· ∉ vowels))
example : removeVowels "abcdef" = "bcdf" := by native_decide
example : removeVowels "abcdef\nghijklm" = "bcdf\nghjklm" := by native_decide
example : removeVowels "aaaaa" = "" := by native_decide
example : removeVowels "aaBAA" = "B" := by native_decide
example : removeVowels "zbcd" = "zbcd" := by native_decide
theorem IsSubseq.length_le {s t : String} (hst : IsSubseq s t) :
s.length ≤ t.length :=
List.Sublist.length_le hst
theorem IsSubseq.removeVowels {s t : String} (hst : IsSubseq s t) :
IsSubseq (removeVowels s) (removeVowels t) := by
simpa [IsSubseq, _root_.removeVowels] using hst.filter _
theorem removeVowels_eq_self {s : String} :
removeVowels s = s ↔ NoVowels s := by
simp [String.ext_iff, NoVowels, removeVowels]
theorem removeVowels_correct : RemoveVowelsIff removeVowels := by
simp [RemoveVowelsIff]
intro s
constructor
· simp [NoVowels, removeVowels, IsSubseq]
· simp only [and_imp]
intro y hnv hss hle
rw [← removeVowels_eq_self.2 hnv]
exact IsSubseq.length_le (IsSubseq.removeVowels hss)
/-!
## Prompt
```python3
def remove_vowels(text):
"""
remove_vowels is a function that takes string and returns string without vowels.
>>> remove_vowels('')
''
>>> remove_vowels("abcdef\nghijklm")
'bcdf\nghjklm'
>>> remove_vowels('abcdef')
'bcdf'
>>> remove_vowels('aaaaa')
''
>>> remove_vowels('aaBAA')
'B'
>>> remove_vowels('zbcd')
'zbcd'
"""
```
## Canonical solution
```python3
return "".join([s for s in text if s.lower() not in ["a", "e", "i", "o", "u"]])
```
## Tests
```python3
METADATA = {}
def check(candidate):
assert candidate('') == ''
assert candidate("abcdef\nghijklm") == 'bcdf\nghjklm'
assert candidate('fedcba') == 'fdcb'
assert candidate('eeeee') == ''
assert candidate('acBAA') == 'cB'
assert candidate('EcBOO') == 'cB'
assert candidate('ybcd') == 'ybcd'
```
-/