diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-12-22 18:31:14 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2023-12-22 18:31:14 +0100 |
commit | 7a5f1983f9189422ad5e12afde11d11bec30a3f1 (patch) | |
tree | 46a02028e2712beaad7cf0886696ff7cd37798cf /aoc-2020-gleam/src/days/day17.gleam | |
parent | d8e183f02f67522d94deafa328e19b3081ca41be (diff) | |
download | gleam_aoc2020-7a5f1983f9189422ad5e12afde11d11bec30a3f1.tar.gz gleam_aoc2020-7a5f1983f9189422ad5e12afde11d11bec30a3f1.zip |
Solve part 1 of day 20
Diffstat (limited to 'aoc-2020-gleam/src/days/day17.gleam')
-rw-r--r-- | aoc-2020-gleam/src/days/day17.gleam | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/aoc-2020-gleam/src/days/day17.gleam b/aoc-2020-gleam/src/days/day17.gleam index e17439c..ad6e22e 100644 --- a/aoc-2020-gleam/src/days/day17.gleam +++ b/aoc-2020-gleam/src/days/day17.gleam @@ -1,31 +1,11 @@ import gleam/io -import gleam/list import gleam/bool -import gleam/string as str import gleam/set.{type Set} +import util/grid import util/input_util import util/pos3 import util/pos4 -fn parse_grid(input: String, with constructor: fn(Int, Int) -> a) -> Set(a) { - input - |> str.split(on: "\n") - |> list.index_map(with: fn(line, y) { - line - |> str.to_graphemes - |> list.index_map(with: fn(grapheme, x) { - case grapheme { - "#" -> [constructor(x, y)] - "." -> [] - _ -> panic - } - }) - |> list.flatten - }) - |> list.flatten - |> set.from_list -} - fn cycle( grid: Set(a), with neighbours: fn(a) -> Set(a), @@ -60,14 +40,14 @@ fn cycle( fn part1(input: String) -> Int { input - |> parse_grid(with: fn(x, y) { #(x, y, 0) }) + |> grid.parse_grid(with: fn(x, y) { #(x, y, 0) }) |> cycle(with: pos3.neighbours26, by: 6) |> set.size } fn part2(input: String) -> Int { input - |> parse_grid(with: fn(x, y) { #(x, y, 0, 0) }) + |> grid.parse_grid(with: fn(x, y) { #(x, y, 0, 0) }) |> cycle(with: pos4.neighbours80, by: 6) |> set.size } |