diff options
Diffstat (limited to 'aoc-2020-gleam/src/days/day07.gleam')
-rw-r--r-- | aoc-2020-gleam/src/days/day07.gleam | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/aoc-2020-gleam/src/days/day07.gleam b/aoc-2020-gleam/src/days/day07.gleam index 2671d72..cfde3e6 100644 --- a/aoc-2020-gleam/src/days/day07.gleam +++ b/aoc-2020-gleam/src/days/day07.gleam @@ -4,8 +4,8 @@ import gleam/list import gleam/pair import gleam/result as res import gleam/function as fun -import gleam/map.{Map} -import gleam/iterator.{Iterator} as iter +import gleam/dict.{type Dict} +import gleam/iterator.{type Iterator} as iter import ext/genericx as genx import ext/resultx as resx import ext/iteratorx as iterx @@ -22,7 +22,7 @@ type BagEdge = #(BagId, Int) type BagGraph = - Map(BagId, List(BagEdge)) + Dict(BagId, List(BagEdge)) type BagNeighbourFun = fn(BagId) -> Iterator(BagId) @@ -44,7 +44,7 @@ fn parse_graph(lines: List(String)) -> BagGraph { |> p.skip_ws |> p.skip(p.then(p.literal("bag"), p.opt(p.literal("s")))) |> p.sep1(by: p.literal(", ")), - else: p.literal("no other bags") + otherwise: p.literal("no other bags") |> p.replace(with: []), )) |> p.skip(p.literal(".")) @@ -54,13 +54,13 @@ fn parse_graph(lines: List(String)) -> BagGraph { p.parse_entire(_, with: line_parser), resx.assert_unwrap, )) - |> map.from_list + |> dict.from_list } fn neighbour_fun(graph: BagGraph) -> BagNeighbourFun { fn(bag) { graph - |> map.get(bag) + |> dict.get(bag) |> resx.assert_unwrap |> list.map(with: pair.first) |> iter.from_list @@ -70,7 +70,7 @@ fn neighbour_fun(graph: BagGraph) -> BagNeighbourFun { fn bag_count(of bag: BagId, in graph: BagGraph) -> Int { list.fold( over: graph - |> map.get(bag) + |> dict.get(bag) |> res.unwrap(or: []), from: 1, with: fn(sum, edge) { @@ -85,9 +85,9 @@ fn part1(lines: List(String)) -> Int { let neighbours = neighbour_fun(graph) graph - |> map.keys + |> dict.keys |> iter.from_list - |> iter.filter(for: genx.different(_, than: special_bag)) + |> iter.filter(keeping: genx.different(_, than: special_bag)) |> iterx.count(satisfying: fn(start) { start |> graph.dfs(with: neighbours) @@ -102,9 +102,9 @@ fn part2(lines: List(String)) -> Int { } pub fn main() -> Nil { - let test = input_util.read_lines("test07") - let assert 4 = part1(test) - let assert 32 = part2(test) + let testing = input_util.read_lines("test07") + let assert 4 = part1(testing) + let assert 32 = part2(testing) let input = input_util.read_lines("day07") io.debug(part1(input)) |