Skip to content

Commit

Permalink
Just find largest rather than sort day 22
Browse files Browse the repository at this point in the history
  • Loading branch information
devries committed Dec 23, 2024
1 parent 0b865bb commit 06e3ce1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/day22/solution.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import gleam/dict.{type Dict}
import gleam/int
import gleam/io
import gleam/list
import gleam/order
import gleam/pair
import gleam/result
import gleam/yielder
Expand Down Expand Up @@ -57,8 +58,12 @@ pub fn solve_p2(lines: List(String)) -> Result(String, String) {
})
})
|> dict.to_list
|> list.sort(fn(a, b) { int.compare(a.1, b.1) })
|> list.last
|> list.reduce(fn(max, o) {
case int.compare(o.1, max.1) {
order.Gt -> o
_ -> max
}
})
|> result.replace_error("Something went wront")
})

Expand Down

0 comments on commit 06e3ce1

Please sign in to comment.