day_4
The general idea is to split the incoming lines into a 2D array of single characters, then we can iterate over sliding windows of 4 characters horizontally, vertically and diagonally and check for “XMAS” ans “SAMX” in these windows, adding to the count.
Part 2 is very similar, only we check each element’s cross value which we first get as a list of list of strings.
(This solution would benefit from using the shared grid
module, but I haven’t built that at that time).
Functions
pub fn at(data: List(a), index: Int) -> Result(a, Nil)
Gets the entry of a 1D-List at a given index
pub fn at_xy(data: List(List(a)), y: Int, x: Int) -> a
Gets the entry at a 2D-List given xy index
pub fn count_crosses(crosses: List(List(String))) -> Int
pub fn get_chunks(
data: List(List(String)),
chunk_size: Int,
) -> List(List(List(String)))
Get nxn chunks from a bigger mxm grid
pub fn get_crosses(
data: List(List(String)),
) -> List(List(String))
Gets all 3-line Crosses from a given grid
pub fn get_diagonals(
data: List(List(String)),
) -> List(List(String))
Gets all 4 line diagonals from a given grid