diff options
author | Hunky Jimpjorps <thechairman@thechairman.info> | 2023-12-12 07:07:15 -0500 |
---|---|---|
committer | Hunky Jimpjorps <thechairman@thechairman.info> | 2023-12-12 07:07:15 -0500 |
commit | b76edb1587e71376cedb4a81ad1ca4ce20ba59fb (patch) | |
tree | a945c0bbd4300b65a9bd7fcfdbdd596e8eeca6d1 /aoc2023/src/utilities | |
parent | 6a634c91145fab5b8ddb3af79c393607cd6272b6 (diff) | |
download | gleam_aoc-b76edb1587e71376cedb4a81ad1ca4ce20ba59fb.tar.gz gleam_aoc-b76edb1587e71376cedb4a81ad1ca4ce20ba59fb.zip |
day 12 tweaks
Diffstat (limited to 'aoc2023/src/utilities')
-rw-r--r-- | aoc2023/src/utilities/array2d.gleam | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/aoc2023/src/utilities/array2d.gleam b/aoc2023/src/utilities/array2d.gleam new file mode 100644 index 0000000..1ad824c --- /dev/null +++ b/aoc2023/src/utilities/array2d.gleam @@ -0,0 +1,27 @@ +import gleam/list +import gleam/dict.{type Dict} +import gleam/string + +pub type Posn { + Posn(x: Int, y: Int) +} + +pub type Array2D(a) = + Dict(Posn, a) + +pub fn to_2d_array(xss: List(List(a))) -> Array2D(a) { + { + use x, row <- list.index_map(xss) + use y, cell <- list.index_map(row) + #(Posn(x, y), cell) + } + |> list.flatten + |> dict.from_list +} + +pub fn parse_grid(str: String) -> Array2D(String) { + str + |> string.split("\n") + |> list.map(string.to_graphemes) + |> to_2d_array +} |