forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval13.lean
More file actions
73 lines (53 loc) · 1.33 KB
/
HumanEval13.lean
File metadata and controls
73 lines (53 loc) · 1.33 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
/-!
## Implementation
There is nothing to implement: The standard library provides `Int.gcd` out of the box.
## Tests
-/
example : Int.gcd 3 7 = 1 := by cbv
example : Int.gcd 10 15 = 5 := by cbv
example : Int.gcd 49 14 = 7 := by cbv
example : Int.gcd 144 60 = 12 := by cbv
/-!
## Verification
-/
/-- info: Int.dvd_gcd_iff {a b : Int} {c : Nat} : c ∣ a.gcd b ↔ ↑c ∣ a ∧ ↑c ∣ b -/
#guard_msgs in
#check Int.dvd_gcd_iff
/-- info: Int.dvd_coe_gcd_iff {a b c : Int} : c ∣ ↑(a.gcd b) ↔ c ∣ a ∧ c ∣ b -/
#guard_msgs in
#check Int.dvd_coe_gcd_iff
theorem Int.gcd_le_of_dvd {a b : Int} {c : Nat}
(h : (c : Int) ∣ a ∧ (c : Int) ∣ b) (hpos : 0 < a ∨ 0 < b) :
c ≤ a.gcd b := by
apply Nat.le_of_dvd <;> grind [Int.dvd_gcd_iff]
/-!
## Prompt
```python3
def greatest_common_divisor(a: int, b: int) -> int:
""" Return a greatest common divisor of two integers a and b
>>> greatest_common_divisor(3, 5)
1
>>> greatest_common_divisor(25, 15)
5
"""
```
## Canonical solution
```python3
while b:
a, b = b, a % b
return a
```
## Tests
```python3
METADATA = {
'author': 'jt',
'dataset': 'test'
}
def check(candidate):
assert candidate(3, 7) == 1
assert candidate(10, 15) == 5
assert candidate(49, 14) == 7
assert candidate(144, 60) == 12
```
-/