Skip to content

Commit 8dd1adf

Browse files
committed
WIP
1 parent 0a3752e commit 8dd1adf

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

HumanEvalLean/HumanEval79.lean

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
module
22

3-
def decimal_to_binary : Unit :=
4-
()
3+
def decimalToBinary (n : Nat) : String :=
4+
"db" ++ String.ofList (Nat.toDigits 2 n) ++ "db"
5+
6+
example : decimalToBinary 0 = "db0db" := by native_decide
7+
example : decimalToBinary 15 = "db1111db" := by native_decide
8+
example : decimalToBinary 32 = "db100000db" := by native_decide
9+
example : decimalToBinary 103 = "db1100111db" := by native_decide
10+
11+
section
12+
13+
open String.Slice.Pattern
14+
15+
@[simp]
16+
theorem String.dropPrefix?_eq_none_iff {ρ : Type} {pat : ρ} [ForwardPattern pat] [LawfulForwardPattern pat]
17+
{s : String} : s.dropPrefix? pat = none ↔ s.startsWith pat = false := by
18+
simp [dropPrefix?_eq_dropPrefix?_toSlice, startsWith_eq_startsWith_toSlice]
19+
20+
public instance {pat : String.Slice} : LawfulForwardPattern pat := sorry
21+
public instance {pat : String} : LawfulForwardPattern pat := sorry
22+
23+
24+
end
25+
26+
theorem toNat?_decimalToBinary {n : Nat} :
27+
((decimalToBinary n).dropPrefix? "db").any
28+
(fun withoutPrefix => (withoutPrefix.dropSuffix? "db").any
29+
(fun withoutSuffix => Nat.ofDigitChars b withoutSuffix.copy.toList 0 == n)) := by
30+
simp [decimalToBinary, Option.any_eq_true]
31+
match h : ("db" ++ String.ofList (Nat.toDigits 2 n) ++ "db").dropPrefix? "db" with
32+
| none => simp at h
33+
| some y =>
34+
simp
35+
have := String.eq_append_of_dropPrefix?_string_eq_some h
36+
match h' : y.dropSuffix? "db" with
37+
| none => simp at h'
38+
| some y' => sorry
39+
40+
41+
542

643
/-!
744
## Prompt
@@ -43,4 +80,4 @@ def check(candidate):
4380
assert True, "This prints if this assert fails 2 (also good for debugging!)"
4481
4582
```
46-
-/
83+
-/

0 commit comments

Comments
 (0)