-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHumanEval34.lean
More file actions
63 lines (40 loc) · 1.3 KB
/
HumanEval34.lean
File metadata and controls
63 lines (40 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
module
public import Std
open Std
public section
/-! ## Implementation -/
def unique (xs : Array Nat) : Array Nat :=
(TreeSet.ofList xs.toList).toArray -- TODO: use `ofArray` as soon as there are lemmas for it
/-! ## Tests -/
example : unique #[5, 3, 5, 2, 3, 3, 9, 0, 123] = #[0, 2, 3, 5, 9, 123] := by native_decide
/-! ## Verification -/
theorem pairwise_lt_unique {xs : Array Nat} :
(unique xs).toList.Pairwise (· < ·) := by
-- ideally, we'd have `ordered_toArray`
simpa [unique, ← TreeSet.toArray_toList, compare_eq_lt] using TreeSet.ordered_toList (α := Nat) (cmp := compare)
theorem pairwise_ne_unique {xs : Array Nat} :
(unique xs).toList.Pairwise ( · ≠ ·) := by
simpa [unique, ← TreeSet.toArray_toList, compare_ne_eq] using TreeSet.distinct_toList (α := Nat) (cmp := compare)
theorem mem_unique_iff {xs : Array Nat} {x : Nat} :
x ∈ unique xs ↔ x ∈ xs := by
grind [unique]
/-!
## Prompt
```python3
def unique(l: list):
"""Return sorted unique elements in a list
>>> unique([5, 3, 5, 2, 3, 3, 9, 0, 123])
[0, 2, 3, 5, 9, 123]
"""
```
## Canonical solution
```python3
return sorted(list(set(l)))
```
## Tests
```python3
METADATA = {}
def check(candidate):
assert candidate([5, 3, 5, 2, 3, 3, 9, 0, 123]) == [0, 2, 3, 5, 9, 123]
```
-/