aboutsummaryrefslogtreecommitdiff
path: root/aoc-2020-gleam/src/days/day24.gleam
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 12:47:11 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2023-12-23 12:47:11 +0100
commit5aa24ac572ab5451e187f9accfa6833634c58215 (patch)
tree45b9daab20e182dcc5f65ec0271727fb847f6e7d /aoc-2020-gleam/src/days/day24.gleam
parent1b8b85dd5f0aead5fb97ee9d8aa99d877c6a79e7 (diff)
downloadgleam_aoc2020-5aa24ac572ab5451e187f9accfa6833634c58215.tar.gz
gleam_aoc2020-5aa24ac572ab5451e187f9accfa6833634c58215.zip
Solve part 1 of day 24
Diffstat (limited to 'aoc-2020-gleam/src/days/day24.gleam')
-rw-r--r--aoc-2020-gleam/src/days/day24.gleam51
1 files changed, 51 insertions, 0 deletions
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
+}