From 5aa24ac572ab5451e187f9accfa6833634c58215 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Sat, 23 Dec 2023 12:47:11 +0100 Subject: Solve part 1 of day 24 --- aoc-2020-gleam/src/days/day24.gleam | 51 +++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 aoc-2020-gleam/src/days/day24.gleam (limited to 'aoc-2020-gleam/src/days/day24.gleam') diff --git a/aoc-2020-gleam/src/days/day24.gleam b/aoc-2020-gleam/src/days/day24.gleam new file mode 100644 index 0000000..66bedb8 --- /dev/null +++ b/aoc-2020-gleam/src/days/day24.gleam @@ -0,0 +1,51 @@ +import gleam/io +import gleam/set +import gleam/list +import ext/setx +import ext/resultx as resx +import util/input_util +import util/parser as p +import util/hex.{type Hex} + +fn parse_tiles(lines: List(String)) -> List(Hex) { + let tile_parser = + [ + p.replace(p.literal("e"), with: hex.e), + p.replace(p.literal("se"), with: hex.se), + p.replace(p.literal("sw"), with: hex.sw), + p.replace(p.literal("w"), with: hex.w), + p.replace(p.literal("nw"), with: hex.nw), + p.replace(p.literal("ne"), with: hex.ne), + ] + |> p.any + |> p.many1 + |> p.map(with: list.fold(over: _, from: hex.zero, with: hex.add)) + + list.map(lines, with: fn(line) { + line + |> p.parse_entire(with: tile_parser) + |> resx.assert_unwrap + }) +} + +fn part1(lines: List(String)) -> Int { + let tiles = parse_tiles(lines) + let blacks = list.fold(over: tiles, from: set.new(), with: setx.toggle) + set.size(blacks) +} + +fn part2(lines: List(String)) -> Nil { + Nil +} + +pub fn main() -> Nil { + let testing = input_util.read_lines("test24") + let assert 10 = part1(testing) + io.debug(part2(testing)) + + let input = input_util.read_lines("day24") + io.debug(part1(input)) + io.debug(part2(input)) + + Nil +} -- cgit v1.2.3