Skip to content

Commit 0fe8cae

Browse files
authored
48 (#296)
1 parent b5f637a commit 0fe8cae

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

HumanEvalLean/HumanEval48.lean

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
module
2+
import Std
23

3-
def is_palindrome : Unit :=
4-
()
4+
open Std
5+
6+
def isPalindrome (s : String) : Bool :=
7+
s.chars.zip s.revChars |>.all (fun p => p.1 == p.2)
8+
9+
example : isPalindrome "" = true := by native_decide
10+
example : isPalindrome "aba" = true := by native_decide
11+
example : isPalindrome "aaaaa" = true := by native_decide
12+
example : isPalindrome "zbcd" = false := by native_decide
13+
example : isPalindrome "xywyx" = true := by native_decide
14+
example : isPalindrome "xywyz" = false := by native_decide
15+
example : isPalindrome "xywxz" = false := by native_decide
16+
17+
theorem isPalindome_iff {s : String} : isPalindrome s ↔ s.toList = s.toList.reverse := by
18+
simp [isPalindrome, ← Iter.all_toList, List.mem_iff_getElem, List.ext_getElem_iff]
19+
grind
520

621
/-!
722
## Prompt
@@ -50,4 +65,4 @@ def check(candidate):
5065
assert candidate('xywzx') == False
5166
5267
```
53-
-/
68+
-/

0 commit comments

Comments
 (0)