diff options
author | J.J <thechairman@thechairman.info> | 2023-12-17 22:56:53 -0500 |
---|---|---|
committer | J.J <thechairman@thechairman.info> | 2023-12-17 22:56:53 -0500 |
commit | 33ed65c88973597c07409a151fd5ced3cf6c5cef (patch) | |
tree | f764d71ce4359509455ea6f7d1d6fc4e98c17c18 /aoc2023/src/utilities | |
parent | 83199de370f15c961502dc37cc7fc09e2be2030f (diff) | |
download | gleam_aoc-33ed65c88973597c07409a151fd5ced3cf6c5cef.tar.gz gleam_aoc-33ed65c88973597c07409a151fd5ced3cf6c5cef.zip |
day 17 gleam incomplete; need priority queue implementation?
Diffstat (limited to 'aoc2023/src/utilities')
-rw-r--r-- | aoc2023/src/utilities/array2d.gleam | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/aoc2023/src/utilities/array2d.gleam b/aoc2023/src/utilities/array2d.gleam index 83ec8ae..9d3b966 100644 --- a/aoc2023/src/utilities/array2d.gleam +++ b/aoc2023/src/utilities/array2d.gleam @@ -1,6 +1,7 @@ import gleam/list import gleam/dict.{type Dict} import gleam/string +import gleam/int pub type Posn { Posn(r: Int, c: Int) @@ -25,9 +26,25 @@ pub fn to_2d_array(xss: List(List(a))) -> Array2D(a) { |> dict.from_list } -pub fn parse_grid(str: String) -> Array2D(String) { +pub fn to_2d_intarray(xss: List(List(String))) -> Array2D(Int) { + { + use r, row <- list.index_map(xss) + use c, cell <- list.index_map(row) + let assert Ok(n) = int.parse(cell) + #(Posn(r, c), n) + } + |> list.flatten + |> dict.from_list +} + +pub fn to_list_of_lists(str: String) -> List(List(String)) { str |> string.split("\n") |> list.map(string.to_graphemes) +} + +pub fn parse_grid(str: String) -> Array2D(String) { + str + |> to_list_of_lists |> to_2d_array } |