Skip to content

Commit 3ec4d95

Browse files
committed
use combination_pairs on advice of LittleLily in gleam discord
1 parent f752838 commit 3ec4d95

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

src/day08/solution.gleam

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,8 @@ pub fn solve_p1(lines: List(String), connections: Int) -> Result(String, String)
3030

3131
let closest_boxes =
3232
boxes
33-
|> list.combinations(2)
34-
|> list.map(fn(pair) {
35-
case pair {
36-
[b1, b2] -> #(#(b1, b2), dsq_boxes(b1, b2))
37-
_ -> panic as "expected a pair of junctions"
38-
}
39-
})
33+
|> list.combination_pairs
34+
|> list.map(fn(pair) { #(pair, dsq_boxes(pair.0, pair.1)) })
4035
|> list.sort(fn(v1, v2) { int.compare(v1.1, v2.1) })
4136
|> list.take(connections)
4237
|> list.map(fn(t) { t.0 })
@@ -63,13 +58,8 @@ pub fn solve_p2(lines: List(String)) -> Result(String, String) {
6358

6459
let closest_boxes =
6560
boxes
66-
|> list.combinations(2)
67-
|> list.map(fn(pair) {
68-
case pair {
69-
[b1, b2] -> #(#(b1, b2), dsq_boxes(b1, b2))
70-
_ -> panic as "expected a pair of junctions"
71-
}
72-
})
61+
|> list.combination_pairs
62+
|> list.map(fn(pair) { #(pair, dsq_boxes(pair.0, pair.1)) })
7363
|> list.sort(fn(v1, v2) { int.compare(v1.1, v2.1) })
7464
|> list.map(fn(t) { t.0 })
7565

0 commit comments

Comments
 (0)