blob: d7d05f8352f6b85e851adf5fe0a97672655e5a03 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import gleam/list
import gleam/dict.{type Dict}
import gleam/string
pub type Posn {
Posn(r: Int, c: Int)
}
pub type Array2D(a) =
Dict(Posn, a)
pub fn to_2d_array(xss: List(List(a))) -> Array2D(a) {
{
use r, row <- list.index_map(xss)
use c, cell <- list.index_map(row)
#(Posn(r, c), 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
}
|