Skip to content

Commit c08d44f

Browse files
committed
Initial commit
0 parents  commit c08d44f

File tree

174 files changed

+8954
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+8954
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Lean Action CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: leanprover/lean-action@v1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.lake

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"editor.rulers": [
3+
100
4+
]
5+
}

CreateScaffold.lean

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Lean.Data.Json.FromToJson
2+
import Lean.Data.Json.Parser
3+
4+
namespace HumanEvalLean.CreateScaffold
5+
6+
structure Task where
7+
task_id : String
8+
prompt : String
9+
entry_point : String
10+
canonical_solution : String
11+
test : String
12+
deriving Repr, Lean.FromJson
13+
14+
def Task.num? (t : Task) : Option Nat :=
15+
t.task_id.dropPrefix? "HumanEval/" |>.map (·.toString) |>.bind String.toNat?
16+
17+
instance : ToString Task where
18+
toString t := repr t |>.pretty
19+
20+
def readFile (filename : System.FilePath) : IO (List Task) := do
21+
let lines := (← IO.FS.readFile filename).splitOn "\n" |>.filter (fun l => !l.isEmpty)
22+
lines.mapM fun line => IO.ofExcept (Lean.Json.parse line >>= Lean.FromJson.fromJson?)
23+
24+
def createScaffoldForTask (t : Task) : IO Unit := do
25+
let some num := t.num? | throw (IO.userError "ill-formed task id")
26+
let fileName := s!"HumanEvalLean/HumanEval{num}.lean"
27+
let content := s!"def {t.entry_point} : Unit :=\n ()\n\n/-!\n## Prompt\n\n```python3\n{t.prompt}```\n\n## Canonical solution\n\n```python3\n{t.canonical_solution}```\n\n## Tests\n\n```python3\n{t.test}```\n-/"
28+
IO.FS.writeFile fileName content
29+
30+
def createScaffold (filename : String) : IO Unit := do
31+
let tasks ← HumanEvalLean.CreateScaffold.readFile filename
32+
tasks.forM createScaffoldForTask
33+
34+
end HumanEvalLean.CreateScaffold
35+
36+
def main (args : List String) : IO Unit := do
37+
if let [filename] := args then do
38+
HumanEvalLean.CreateScaffold.createScaffold filename
39+
else
40+
IO.println "Expected exactly one argument with a filename"

HumanEvalLean.lean

Whitespace-only changes.

HumanEvalLean/HumanEval0.lean

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
def has_close_elements : Unit :=
2+
()
3+
4+
/-!
5+
## Prompt
6+
7+
```python3
8+
from typing import List
9+
10+
11+
def has_close_elements(numbers: List[float], threshold: float) -> bool:
12+
""" Check if in given list of numbers, are any two numbers closer to each other than
13+
given threshold.
14+
>>> has_close_elements([1.0, 2.0, 3.0], 0.5)
15+
False
16+
>>> has_close_elements([1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3)
17+
True
18+
"""
19+
```
20+
21+
## Canonical solution
22+
23+
```python3
24+
for idx, elem in enumerate(numbers):
25+
for idx2, elem2 in enumerate(numbers):
26+
if idx != idx2:
27+
distance = abs(elem - elem2)
28+
if distance < threshold:
29+
return True
30+
31+
return False
32+
```
33+
34+
## Tests
35+
36+
```python3
37+
38+
39+
METADATA = {
40+
'author': 'jt',
41+
'dataset': 'test'
42+
}
43+
44+
45+
def check(candidate):
46+
assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.3) == True
47+
assert candidate([1.0, 2.0, 3.9, 4.0, 5.0, 2.2], 0.05) == False
48+
assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.95) == True
49+
assert candidate([1.0, 2.0, 5.9, 4.0, 5.0], 0.8) == False
50+
assert candidate([1.0, 2.0, 3.0, 4.0, 5.0, 2.0], 0.1) == True
51+
assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 1.0) == True
52+
assert candidate([1.1, 2.2, 3.1, 4.1, 5.1], 0.5) == False
53+
54+
```
55+
-/

HumanEvalLean/HumanEval1.lean

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
def separate_paren_groups : Unit :=
2+
()
3+
4+
/-!
5+
## Prompt
6+
7+
```python3
8+
from typing import List
9+
10+
11+
def separate_paren_groups(paren_string: str) -> List[str]:
12+
""" Input to this function is a string containing multiple groups of nested parentheses. Your goal is to
13+
separate those group into separate strings and return the list of those.
14+
Separate groups are balanced (each open brace is properly closed) and not nested within each other
15+
Ignore any spaces in the input string.
16+
>>> separate_paren_groups('( ) (( )) (( )( ))')
17+
['()', '(())', '(()())']
18+
"""
19+
```
20+
21+
## Canonical solution
22+
23+
```python3
24+
result = []
25+
current_string = []
26+
current_depth = 0
27+
28+
for c in paren_string:
29+
if c == '(':
30+
current_depth += 1
31+
current_string.append(c)
32+
elif c == ')':
33+
current_depth -= 1
34+
current_string.append(c)
35+
36+
if current_depth == 0:
37+
result.append(''.join(current_string))
38+
current_string.clear()
39+
40+
return result
41+
```
42+
43+
## Tests
44+
45+
```python3
46+
47+
48+
METADATA = {
49+
'author': 'jt',
50+
'dataset': 'test'
51+
}
52+
53+
54+
def check(candidate):
55+
assert candidate('(()()) ((())) () ((())()())') == [
56+
'(()())', '((()))', '()', '((())()())'
57+
]
58+
assert candidate('() (()) ((())) (((())))') == [
59+
'()', '(())', '((()))', '(((())))'
60+
]
61+
assert candidate('(()(())((())))') == [
62+
'(()(())((())))'
63+
]
64+
assert candidate('( ) (( )) (( )( ))') == ['()', '(())', '(()())']
65+
```
66+
-/

HumanEvalLean/HumanEval10.lean

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
def make_palindrome : Unit :=
2+
()
3+
4+
/-!
5+
## Prompt
6+
7+
```python3
8+
9+
10+
def is_palindrome(string: str) -> bool:
11+
""" Test if given string is a palindrome """
12+
return string == string[::-1]
13+
14+
15+
def make_palindrome(string: str) -> str:
16+
""" Find the shortest palindrome that begins with a supplied string.
17+
Algorithm idea is simple:
18+
- Find the longest postfix of supplied string that is a palindrome.
19+
- Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
20+
>>> make_palindrome('')
21+
''
22+
>>> make_palindrome('cat')
23+
'catac'
24+
>>> make_palindrome('cata')
25+
'catac'
26+
"""
27+
```
28+
29+
## Canonical solution
30+
31+
```python3
32+
if not string:
33+
return ''
34+
35+
beginning_of_suffix = 0
36+
37+
while not is_palindrome(string[beginning_of_suffix:]):
38+
beginning_of_suffix += 1
39+
40+
return string + string[:beginning_of_suffix][::-1]
41+
```
42+
43+
## Tests
44+
45+
```python3
46+
47+
48+
METADATA = {
49+
'author': 'jt',
50+
'dataset': 'test'
51+
}
52+
53+
54+
def check(candidate):
55+
assert candidate('') == ''
56+
assert candidate('x') == 'x'
57+
assert candidate('xyz') == 'xyzyx'
58+
assert candidate('xyx') == 'xyx'
59+
assert candidate('jerry') == 'jerryrrej'
60+
```
61+
-/

HumanEvalLean/HumanEval100.lean

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
def make_a_pile : Unit :=
2+
()
3+
4+
/-!
5+
## Prompt
6+
7+
```python3
8+
9+
def make_a_pile(n):
10+
"""
11+
Given a positive integer n, you have to make a pile of n levels of stones.
12+
The first level has n stones.
13+
The number of stones in the next level is:
14+
- the next odd number if n is odd.
15+
- the next even number if n is even.
16+
Return the number of stones in each level in a list, where element at index
17+
i represents the number of stones in the level (i+1).
18+
19+
Examples:
20+
>>> make_a_pile(3)
21+
[3, 5, 7]
22+
"""
23+
```
24+
25+
## Canonical solution
26+
27+
```python3
28+
return [n + 2*i for i in range(n)]
29+
```
30+
31+
## Tests
32+
33+
```python3
34+
def check(candidate):
35+
36+
# Check some simple cases
37+
assert candidate(3) == [3, 5, 7], "Test 3"
38+
assert candidate(4) == [4,6,8,10], "Test 4"
39+
assert candidate(5) == [5, 7, 9, 11, 13]
40+
assert candidate(6) == [6, 8, 10, 12, 14, 16]
41+
assert candidate(8) == [8, 10, 12, 14, 16, 18, 20, 22]
42+
43+
# Check some edge cases that are easy to work out by hand.
44+
assert True, "This prints if this assert fails 2 (also good for debugging!)"
45+
46+
```
47+
-/

HumanEvalLean/HumanEval101.lean

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
def words_string : Unit :=
2+
()
3+
4+
/-!
5+
## Prompt
6+
7+
```python3
8+
9+
def words_string(s):
10+
"""
11+
You will be given a string of words separated by commas or spaces. Your task is
12+
to split the string into words and return an array of the words.
13+
14+
For example:
15+
words_string("Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
16+
words_string("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
17+
"""
18+
```
19+
20+
## Canonical solution
21+
22+
```python3
23+
if not s:
24+
return []
25+
26+
s_list = []
27+
28+
for letter in s:
29+
if letter == ',':
30+
s_list.append(' ')
31+
else:
32+
s_list.append(letter)
33+
34+
s_list = "".join(s_list)
35+
return s_list.split()
36+
```
37+
38+
## Tests
39+
40+
```python3
41+
def check(candidate):
42+
43+
# Check some simple cases
44+
assert True, "This prints if this assert fails 1 (good for debugging!)"
45+
assert candidate("Hi, my name is John") == ["Hi", "my", "name", "is", "John"]
46+
assert candidate("One, two, three, four, five, six") == ["One", "two", "three", "four", "five", "six"]
47+
assert candidate("Hi, my name") == ["Hi", "my", "name"]
48+
assert candidate("One,, two, three, four, five, six,") == ["One", "two", "three", "four", "five", "six"]
49+
50+
# Check some edge cases that are easy to work out by hand.
51+
assert True, "This prints if this assert fails 2 (also good for debugging!)"
52+
assert candidate("") == []
53+
assert candidate("ahmed , gamal") == ["ahmed", "gamal"]
54+
55+
```
56+
-/

0 commit comments

Comments
 (0)