11module
2+ import Std.Data.Iterators.Producers.Range
3+ import Std
24
3- def string_sequence : Unit :=
4- ()
5+ def stringSequence (n : Nat) : String :=
6+ Std.Iter.intercalateString.{0 } " " ((0 ...=n).iter.map (String.toSlice ∘ Nat.repr))
7+
8+ example : stringSequence 0 = "0" := by native_decide
9+ example : stringSequence 3 = "0 1 2 3" := by native_decide
10+ example : stringSequence 10 = "0 1 2 3 4 5 6 7 8 9 10" := by native_decide
11+
12+ /-- Calling `stringSequence` and then splitting the result at space characters and attempting to
13+ parse the components into natural numbers yields the sequence `[some 0, some 1, ..., some n]`. -/
14+ theorem map_ofNat?_stringSequence {n : Nat} :
15+ ((stringSequence n).split ' ' ).toList.map String.Slice.toNat? =
16+ (0 ...=n).toList.map Option.some := by
17+ rw [stringSequence, ← String.Slice.toNat?_comp_copy, ← List.map_map,
18+ Std.Iter.intercalateString_eq, String.Slice.toStringToString_eq, String.copy_toSlice]
19+ simp +instances only [String.reduceToSingleton]
20+ rw [String.toList_split_intercalate]
21+ · rw [Std.Iter.toList_map]
22+ simp
23+ · rw [Std.Iter.toList_map]
24+ simp only [Std.Rcc.toList_iter, List.mem_map, Function.comp_apply, ↓Char.isValue,
25+ forall_exists_index, and_imp, forall_apply_eq_imp_iff₂, String.copy_toSlice, Nat.toList_repr]
26+ intro a ha h
27+ simpa using Nat.isDigit_of_mem_toDigits (by decide) (by decide) h
528
629/-!
730## Prompt
@@ -40,4 +63,4 @@ def check(candidate):
4063 assert candidate(3) == '0 1 2 3'
4164 assert candidate(10) == '0 1 2 3 4 5 6 7 8 9 10'
4265```
43- -/
66+ -/
0 commit comments