day_12
Functions
pub fn accumulate_border(
grid: Dict(#(Int, Int), String),
current: #(Int, Int),
border: List(#(Int, Int)),
initial_cell: #(Int, Int),
) -> List(#(Int, Int))
pub fn find_adjacent_element(
cell: #(Int, Int),
from: List(#(Int, Int)),
) -> Result(#(#(Int, Int), List(#(Int, Int))), Nil)
pub fn find_first_border_cell(
grid: Dict(#(Int, Int), String),
region: List(#(Int, Int)),
) -> #(Int, Int)
pub fn find_next_border_cell(
grid: Dict(#(Int, Int), String),
cell: #(Int, Int),
) -> #(Int, Int)
pub fn get_adjacent_cells(pos: #(Int, Int)) -> List(#(Int, Int))
Get the adjacent cells
oAo AXA oAo
For the cell “X” in the middle, the adjacent cells are the ones that can be reached by moving one step in any vertical or horizontal direction. The 4 cross-shaped cells “A” are the adjacent cells.
pub fn get_circumference(
grid: Dict(#(Int, Int), String),
region: List(#(Int, Int)),
) -> Int
Get the circumference for the given region. Note that this assumes contiguousness. Each cell adds a value based on the number of neighbors it has that are in the region. 4 neighbors -> 0 circumference, 3 neighbors -> 1, etc.
pub fn get_region(
grid: Dict(#(Int, Int), String),
candidate_pos: #(Int, Int),
current_value: String,
checked_cells: Dict(#(Int, Int), Bool),
) -> #(List(#(Int, Int)), Dict(#(Int, Int), Bool))
pub fn get_same_adjacents(
grid: Dict(#(Int, Int), String),
cell: #(Int, Int),
) -> List(#(Int, Int))
Get adjacent cells with the same value
pub fn get_same_surrounding(
grid: Dict(#(Int, Int), String),
cell: #(Int, Int),
) -> List(#(Int, Int))
Get surrounding cells with the same value
pub fn get_surrounding_cells(
pos: #(Int, Int),
) -> List(#(Int, Int))
Get the surrounding cells (both direct and diagonal)
oAo AXA oAo
here, the surrounding cells for “X” in the middle are all 8 cells around it. [“o”, “A”, “o”, “A”, “A”, “A”, “o”, “A”]
pub fn has_checked(
regions: List(List(#(Int, Int))),
candidate: #(Int, Int),
) -> Bool
pub fn is_border_cell(
grid: Dict(#(Int, Int), String),
cell: #(Int, Int),
) -> Bool
pub fn sort_boundary(
current_boundary: List(#(Int, Int)),
rest_boundary: List(#(Int, Int)),
) -> List(#(Int, Int))