forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval18.lean
More file actions
50 lines (36 loc) · 841 Bytes
/
HumanEval18.lean
File metadata and controls
50 lines (36 loc) · 841 Bytes
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
def how_many_times : Unit :=
()
/-!
## Prompt
```python3
def how_many_times(string: str, substring: str) -> int:
""" Find how many times a given substring can be found in the original string. Count overlaping cases.
>>> how_many_times('', 'a')
0
>>> how_many_times('aaa', 'a')
3
>>> how_many_times('aaaa', 'aa')
3
"""
```
## Canonical solution
```python3
times = 0
for i in range(len(string) - len(substring) + 1):
if string[i:i+len(substring)] == substring:
times += 1
return times
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate('', 'x') == 0
assert candidate('xyxyxyx', 'x') == 4
assert candidate('cacacacac', 'cac') == 4
assert candidate('john doe', 'john') == 1
```
-/