Skip to content

Commit 4060091

Browse files
committed
tweaks
1 parent c63d0ad commit 4060091

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Aoc2024/Utils.lean

+7-12
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ namespace List
5353

5454
#guard [1, 2, 3].sumBy (λ x => x * x) = 14
5555

56-
def toSet {α:Type} [BEq α] [Hashable α] (xs: List α) : HashSet α :=
57-
HashSet.ofList xs
56+
def toSet {α:Type} [BEq α] [Hashable α] (xs: List α) : HashSet α := HashSet.ofList xs
5857

59-
def slidingPairs (xs: List α) : List (α × α) :=
60-
xs.zip xs.tail
58+
def slidingPairs (xs: List α) : List (α × α) := xs.zip xs.tail
6159

6260
#guard [1, 2, 3, 4].slidingPairs == [(1, 2), (2, 3), (3, 4)]
6361

@@ -141,16 +139,13 @@ namespace List
141139
#guard [1, 2].replicateM 0 == [[]]
142140
#guard [1, 2].replicateM 3 == [[1, 1, 1], [2, 1, 1], [1, 2, 1], [2, 2, 1], [1, 1, 2], [2, 1, 2], [1, 2, 2], [2, 2, 2]]
143141

144-
def eraseAll [BEq α] (x: α) (xs : List α) : List α := xs.filter (· != x)
142+
def eraseAll [BEq α] (x: α) (xs : List α) : List α := xs.filter (· != x)
145143
#guard [1, 2, 3, 2].eraseAll 2 == [1, 3]
146144

147-
def combinations {α} [BEq α] (n : Nat) (xs : List α) : List (List α) :=
148-
match n with
149-
| 0 => [[]]
150-
| n + 1 =>
151-
match xs with
152-
| [] => []
153-
| x :: xs => (xs.combinations n).map (x :: ·) ++ xs.combinations (n + 1)
145+
def combinations {α} [BEq α] : Nat -> List α -> List (List α)
146+
| 0, _ => [[]]
147+
| _ + 1, [] => []
148+
| n + 1, x :: xs => (xs.combinations n).map (x :: ·) ++ xs.combinations (n + 1)
154149

155150
#guard [1, 2, 3].combinations 0 == [[]]
156151
#guard [1, 2, 3].combinations 1 == [[1], [2], [3]]

0 commit comments

Comments
 (0)