forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval27.lean
More file actions
73 lines (51 loc) · 1.64 KB
/
HumanEval27.lean
File metadata and controls
73 lines (51 loc) · 1.64 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
module
def Char.flipCase (c : Char) : Char :=
if c.isLower then
c.toUpper
else if c.isUpper then
c.toLower
else
c
def flipCase (string : String) : String :=
string.map Char.flipCase
example : flipCase "" = "" := by cbv
example : flipCase "Hello!" = "hELLO!" := by cbv
example : flipCase "These violent delights have violent ends" = "tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS" := by cbv
theorem toList_flipCase {string : String} : (flipCase string).toList = string.toList.map Char.flipCase := by
simp [flipCase]
namespace Char
theorem isUpper_flipCase {c : Char} : c.flipCase.isUpper ↔ c.isLower := by
grind [flipCase, isUpper, isLower, toUpper, toLower]
theorem isLower_flipCase {c : Char} : c.flipCase.isLower ↔ c.isUpper := by
grind [flipCase, isUpper, isLower, toUpper, toLower]
theorem toLower_flipCase {c : Char} : c.flipCase.toLower = c.toLower := by
-- https://github.com/leanprover/lean4/issues/13089
simp [flipCase, isUpper, isLower, toUpper, toLower, ← toNat_inj, apply_dite Char.toNat,
apply_ite Char.toNat, UInt32.le_iff_toNat_le]
grind
end Char
/-!
## Prompt
```python3
def flip_case(string: str) -> str:
""" For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
>>> flip_case('Hello')
'hELLO'
"""
```
## Canonical solution
```python3
return string.swapcase()
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('') == ''
assert candidate('Hello!') == 'hELLO!'
assert candidate('These violent delights have violent ends') == 'tHESE VIOLENT DELIGHTS HAVE VIOLENT ENDS'
```
-/