Skip to content

Commit 283f76e

Browse files
authored
86 (#309)
1 parent aece176 commit 283f76e

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

HumanEvalLean/HumanEval86.lean

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

3-
def anti_shuffle : Unit :=
4-
()
3+
def antiShuffle (s : String) : String :=
4+
s.split ' '
5+
|>.map (fun sl => String.ofList (Array.mergeSort sl.chars.toArray).toList)
6+
|>.intercalateString " "
7+
8+
example : antiShuffle "Hi" = "Hi" := by native_decide
9+
example : antiShuffle "hello" = "ehllo" := by native_decide
10+
example : antiShuffle "Hello World!!!" = "Hello !!!Wdlor" := by native_decide
11+
example : antiShuffle "number" = "bemnru" := by native_decide
12+
example : antiShuffle "abcd" = "abcd" := by native_decide
13+
example : antiShuffle "" = "" := by native_decide
14+
example : antiShuffle "Hi. My name is Mister Robot. How are you?" = ".Hi My aemn is Meirst .Rboot How aer ?ouy" := by native_decide
15+
16+
@[simp]
17+
theorem String.toString_eq : (ToString.toString (α := String)) = id := rfl
18+
19+
/-- Taking a list of words, joining them together separated by spaces and calling `antiShuffle` on that
20+
is the same as first sorting the characters in every word and then joining that together. -/
21+
theorem antiShuffle_intercalate {l : List (List Char)} (hl : ∀ s ∈ l, ' ' ∉ s) :
22+
antiShuffle (" ".intercalate (l.map String.ofList)) =
23+
" ".intercalate (l.map (fun s => String.ofList s.mergeSort)) := by
24+
rw [antiShuffle]
25+
simp +instances only [String.reduceToSingleton]
26+
rw [Std.Iter.intercalateString_eq, String.copy_toSlice, Std.Iter.toList_map]
27+
simp only [← Std.Iter.toArray_toList, String.Slice.toList_chars]
28+
have : (fun (sl : String.Slice) => String.ofList (sl.copy.toList.toArray.mergeSort).toList) =
29+
(fun (s : String) => String.ofList (s.toList.toArray.mergeSort).toList) ∘ String.Slice.copy := rfl
30+
simp only [this, ← List.map_map]
31+
rw [String.toList_split_intercalate (by simpa)]
32+
simp only [↓Char.isValue, String.reduceSingleton, List.map_eq_nil_iff, List.map_map]
33+
split
34+
· simp_all
35+
· simp only [String.toString_eq, Function.id_comp, List.map_map]
36+
congr
37+
ext1 s
38+
simp [Array.toList_mergeSort]
539

640
/-!
741
## Prompt
@@ -46,4 +80,4 @@ def check(candidate):
4680
assert True
4781
4882
```
49-
-/
83+
-/

0 commit comments

Comments
 (0)