Skip to content

Commit 13ffc00

Browse files
authored
50 (#297)
1 parent 0fe8cae commit 13ffc00

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

HumanEvalLean/HumanEval50.lean

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

3-
def decode_shift : Unit :=
4-
()
3+
def Char.shiftByFive (c : Char) : Char :=
4+
Char.ofNat ((c.toNat - 'a'.toNat + 5) % 26 + 'a'.toNat)
5+
6+
def Char.unshiftByFive (c : Char) : Char :=
7+
Char.ofNat ((c.toNat - 'a'.toNat + 21) % 26 + 'a'.toNat)
8+
9+
def encodeShift (s : String) : String :=
10+
s.map Char.shiftByFive
11+
12+
def decodeShift (s : String) : String :=
13+
s.map Char.unshiftByFive
14+
15+
@[simp]
16+
theorem Char.toNat_mk {val : UInt32} {h} : (Char.mk val h).toNat = val.toNat := by
17+
simp [← toNat_val]
18+
19+
theorem Char.toNat_ofNat_of_isValidChar {n : Nat} (h : n.isValidChar) : (Char.ofNat n).toNat = n := by
20+
simp [ofNat, h, ofNatAux]
21+
22+
@[simp]
23+
theorem Char.unshiftByFive_shiftByFive {c : Char} (hc : c.isLower) : c.shiftByFive.unshiftByFive = c := by
24+
simp [Char.isLower, Char.shiftByFive, Char.unshiftByFive, UInt32.le_iff_toNat_le,
25+
← Char.toNat_inj] at *
26+
grind [toNat_ofNat_of_isValidChar]
27+
28+
theorem List.map_eq_self {f : α → α} {l : List α} (hf : ∀ a ∈ l, f a = a) : l.map f = l := by
29+
induction l <;> grind
30+
31+
theorem decodeShift_encodeShift (s : String) (hs : ∀ c ∈ s.toList, c.isLower) :
32+
decodeShift (encodeShift s) = s := by
33+
simpa [← String.toList_inj, decodeShift, encodeShift] using
34+
List.map_eq_self (by grind [Char.unshiftByFive_shiftByFive])
535

636
/-!
737
## Prompt
@@ -48,4 +78,4 @@ def check(candidate):
4878
assert candidate(copy.deepcopy(encoded_str)) == str
4979
5080
```
51-
-/
81+
-/

0 commit comments

Comments
 (0)