Skip to content

Commit 06e3ce1

Browse files
committed
Just find largest rather than sort day 22
1 parent 0b865bb commit 06e3ce1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/day22/solution.gleam

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import gleam/dict.{type Dict}
22
import gleam/int
33
import gleam/io
44
import gleam/list
5+
import gleam/order
56
import gleam/pair
67
import gleam/result
78
import gleam/yielder
@@ -57,8 +58,12 @@ pub fn solve_p2(lines: List(String)) -> Result(String, String) {
5758
})
5859
})
5960
|> dict.to_list
60-
|> list.sort(fn(a, b) { int.compare(a.1, b.1) })
61-
|> list.last
61+
|> list.reduce(fn(max, o) {
62+
case int.compare(o.1, max.1) {
63+
order.Gt -> o
64+
_ -> max
65+
}
66+
})
6267
|> result.replace_error("Something went wront")
6368
})
6469

0 commit comments

Comments
 (0)