day_6

This is being solved by a recursive function:

If no “>” or similar character is found, return the 2D array. Otherwise, find that character, check the direction its pointing, and then update the grid:

This also could benefit from using the shared grid module - it also should transform the individual directions in their own types instead of always comparing strings. You can see these sort of ideas develop in the later solutions, for now, I’m a bit too lazy to refactor this. (Also it’s a nice snapshot in time of my gleam-learning journey)

Functions

pub fn check_grid_for_loop(
  grid: Dict(#(Int, Int), String),
  guard: #(#(Int, Int), String),
) -> Bool
pub fn find_guard(
  grid: Dict(#(Int, Int), String),
) -> Result(#(#(Int, Int), String), Nil)
pub fn get_element_index(
  row: List(a),
  element: a,
) -> Result(Int, Nil)
pub fn get_grid_permutations(
  grid: Dict(#(Int, Int), String),
  original_grid: Dict(#(Int, Int), String),
) -> List(Dict(#(Int, Int), String))
pub fn get_guard_column(
  grid: List(List(String)),
  guard_row: List(String),
) -> List(String)
pub fn get_guard_list(
  grid: List(List(String)),
  guard: String,
) -> List(String)
pub fn get_guard_trail(guard_char: String) -> String
pub fn get_next_guard_pos(
  guard: #(#(Int, Int), String),
) -> Result(#(Int, Int), Nil)
pub fn has_guard(grid: List(List(String))) -> Bool
pub fn is_forward_guard(guard: String) -> Bool
pub fn is_vertical_guard(guard: String) -> Bool
pub fn main() -> Nil
pub fn move_guard(
  grid: Dict(#(Int, Int), String),
  guard: #(#(Int, Int), String),
  target: #(Int, Int),
) -> Dict(#(Int, Int), String)
pub fn part_1() -> Int
pub fn part_2() -> Int
pub fn pretty_print(
  grid: Dict(#(Int, Int), String),
) -> Dict(#(Int, Int), String)
pub fn rotate_guard(
  grid: Dict(#(Int, Int), String),
  guard: #(#(Int, Int), String),
) -> Dict(#(Int, Int), String)
pub fn rotate_guard_char(char: String) -> String
pub fn row_contains_guard(row: List(String)) -> Bool
pub fn should_create_permutation(
  grid: Dict(#(Int, Int), String),
  coords: #(Int, Int),
) -> Bool
pub fn solve_grid(
  grid: Dict(#(Int, Int), String),
) -> Dict(#(Int, Int), String)
pub fn solve_grid_loops(
  grid: Dict(#(Int, Int), String),
  previously_seen_grids: List(Dict(#(Int, Int), String)),
) -> Result(Dict(#(Int, Int), String), Nil)
pub fn update_grid(
  grid: Dict(#(Int, Int), String),
  guard: #(#(Int, Int), String),
) -> Dict(#(Int, Int), String)
pub fn update_normalized_row(row: List(String)) -> List(String)
pub fn will_loop(row: List(String)) -> Bool
Search Document