forked from leanprover/human-eval-lean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHumanEval44.lean
More file actions
65 lines (49 loc) · 1.44 KB
/
HumanEval44.lean
File metadata and controls
65 lines (49 loc) · 1.44 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
module
def changeBase (x : Nat) (base : Nat) : String :=
String.ofList (Nat.toDigits base x)
example : changeBase 8 3 = "22" := by native_decide
example : changeBase 9 3 = "100" := by native_decide
example : changeBase 234 2 = "11101010" := by native_decide
example : changeBase 16 2 = "10000" := by native_decide
example : changeBase 8 2 = "1000" := by native_decide
example : changeBase 7 2 = "111" := by native_decide
theorem ofDigitChars_changeBase {x : Nat} {base : Nat} (hb' : 1 < base) (hb : base ≤ 10) :
Nat.ofDigitChars base (changeBase x base).toList 0 = x := by
simp [changeBase, Nat.ofDigitChars_toDigits hb' hb]
/-!
## Prompt
```python3
def change_base(x: int, base: int):
"""Change numerical base of input number x to base.
return string representation after the conversion.
base numbers are less than 10.
>>> change_base(8, 3)
'22'
>>> change_base(8, 2)
'1000'
>>> change_base(7, 2)
'111'
"""
```
## Canonical solution
```python3
ret = ""
while x > 0:
ret = str(x % base) + ret
x //= base
return ret
```
## Tests
```python3
METADATA = {}
def check(candidate):
assert candidate(8, 3) == "22"
assert candidate(9, 3) == "100"
assert candidate(234, 2) == "11101010"
assert candidate(16, 2) == "10000"
assert candidate(8, 2) == "1000"
assert candidate(7, 2) == "111"
for x in range(2, 8):
assert candidate(x, x + 1) == str(x)
```
-/