forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval16.lean
More file actions
75 lines (57 loc) · 2.14 KB
/
HumanEval16.lean
File metadata and controls
75 lines (57 loc) · 2.14 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
module
import Std.Data.Iterators.Consumers.Set
import Std.Data.Iterators.Lemmas.Consumers.Set
import Std.Data.HashSet.Lemmas
open Std
def countDistinctCharacters (s : String) : Nat :=
(s.chars.map Char.toLower).toHashSet.size
example : countDistinctCharacters "" = 0 := by native_decide
example : countDistinctCharacters "abcde" = 5 := by native_decide
example : countDistinctCharacters ("abcde" ++ "cade" ++ "CADE") = 5 := by native_decide
example : countDistinctCharacters "aaaaAAAAaaaa" = 1 := by native_decide
example : countDistinctCharacters "Jerry jERRY JeRRRY" = 5 := by native_decide
theorem countDistinctCharacters_eq {s : String} :
countDistinctCharacters s = (HashSet.ofList (s.toList.map Char.toLower)).size := by
simp [countDistinctCharacters, Iter.toHashSet_equiv_ofList.size_eq]
theorem countDistinctCharacters_empty : countDistinctCharacters "" = 0 := by
simp [countDistinctCharacters_eq]
theorem countDistinctCharacters_push {s : String} {c : Char} :
countDistinctCharacters (s.push c) =
if c.toLower ∈ s.toList.map Char.toLower then
countDistinctCharacters s
else
countDistinctCharacters s + 1 := by
simp only [countDistinctCharacters_eq, String.toList_push, List.map_append, List.map_cons,
List.map_nil, List.mem_map]
rw [HashSet.ofList_equiv_foldl.size_eq, List.foldl_append, List.foldl_cons, List.foldl_nil,
HashSet.size_insert]
simp [← HashSet.ofList_equiv_foldl.mem_iff, ← HashSet.ofList_equiv_foldl.size_eq]
/-!
## Prompt
```python3
def count_distinct_characters(string: str) -> int:
""" Given a string, find out how many distinct characters (regardless of case) does it consist of
>>> count_distinct_characters('xyzXYZ')
3
>>> count_distinct_characters('Jerry')
4
"""
```
## Canonical solution
```python3
return len(set(string.lower()))
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('') == 0
assert candidate('abcde') == 5
assert candidate('abcde' + 'cade' + 'CADE') == 5
assert candidate('aaaaAAAAaaaa') == 1
assert candidate('Jerry jERRY JeRRRY') == 5
```
-/