day_18

Types

pub type Map =
  grid.Grid(MemorySpace)
pub type MemorySpace {
  Safe
  Corrupted
  Path
}

Constructors

  • Safe
  • Corrupted
  • Path

Grid of Safe or Non-Safe spaces with incoming corruption coordinates

pub type MemoryState {
  MemoryState(
    grid: Map,
    incoming_corruptions: List(grid.Position),
  )
}

Constructors

  • MemoryState(grid: Map, incoming_corruptions: List(grid.Position))
pub type Path =
  List(grid.Position)

Functions

pub fn a_star(
  start: #(Int, Int),
  target: #(Int, Int),
  map: Dict(#(Int, Int), MemorySpace),
) -> Result(List(#(Int, Int)), Nil)
pub fn debug_grid(
  grid: Dict(#(Int, Int), MemorySpace),
) -> Dict(#(Int, Int), MemorySpace)
pub fn debug_path(
  path: List(#(Int, Int)),
  map: Dict(#(Int, Int), MemorySpace),
) -> List(#(Int, Int))
pub fn do_a_star(
  f_score: Dict(#(Int, Int), Float),
  g_score: Dict(#(Int, Int), Float),
  came_from: Dict(#(Int, Int), #(Int, Int)),
  target: #(Int, Int),
  open_set: List(#(Int, Int)),
  map: Dict(#(Int, Int), MemorySpace),
) -> Result(List(#(Int, Int)), Nil)
pub fn get_distance(a: #(Int, Int), b: #(Int, Int)) -> Float
pub fn get_grid_at_time(
  memory_state: MemoryState,
  time: Int,
) -> Dict(#(Int, Int), MemorySpace)
pub fn get_heuristic(a: #(Int, Int), b: #(Int, Int)) -> Float
pub fn get_path_length(path: List(#(Int, Int))) -> Int
pub fn get_possible_steps(
  map: Dict(#(Int, Int), MemorySpace),
  position: #(Int, Int),
) -> List(#(Int, Int))
pub fn get_score(
  position: #(Int, Int),
  scores: Dict(#(Int, Int), Float),
) -> Float
pub fn get_surrounding_positions(
  position: #(Int, Int),
) -> List(#(Int, Int))

Get all surrounding positions (in a cross pattern) of a given position.

pub fn handle_neighbors_of_current(
  neighbors: List(#(Int, Int)),
  f_score: Dict(#(Int, Int), Float),
  g_score: Dict(#(Int, Int), Float),
  came_from: Dict(#(Int, Int), #(Int, Int)),
  current: #(Int, Int),
  target: #(Int, Int),
  open_set: List(#(Int, Int)),
  map: Dict(#(Int, Int), MemorySpace),
) -> Result(List(#(Int, Int)), Nil)
pub fn infinity() -> Int
pub fn insert_path(
  grid: Dict(#(Int, Int), MemorySpace),
  path: List(#(Int, Int)),
) -> Dict(#(Int, Int), MemorySpace)
pub fn is_corrupted(
  map: Dict(#(Int, Int), MemorySpace),
  position: #(Int, Int),
) -> Bool
pub fn main() -> Nil
pub fn parse_input(
  input: List(String),
  size: #(Int, Int),
) -> MemoryState
pub fn part_1() -> Int
pub fn part_1_generic(file: String, size: Int, time: Int) -> Int
pub fn part_2() -> Result(#(Int, Int), Nil)
pub fn part_2_generic(
  file: String,
  size: Int,
  offset: Int,
) -> Result(#(Int, Int), Nil)
pub fn part_2_test() -> Result(#(Int, Int), Nil)
pub fn part_test() -> Int
pub fn reconstruct_path(
  came_from: Dict(#(Int, Int), #(Int, Int)),
  current: #(Int, Int),
  total_path: List(#(Int, Int)),
) -> List(#(Int, Int))
pub fn replay_path(
  initial_state: MemoryState,
  path: List(#(Int, Int)),
) -> Dict(#(Int, Int), MemorySpace)
pub fn solve_for_time(
  state: MemoryState,
  size: Int,
  time: Int,
) -> Result(List(#(Int, Int)), Nil)
pub fn solve_grid(
  memory_state: MemoryState,
  current_position: #(Int, Int),
  current_path: List(#(Int, Int)),
  paths: List(List(#(Int, Int))),
  target_position: #(Int, Int),
  already_checked: Dict(#(Int, Int), Bool),
  came_from: Dict(#(Int, Int), #(Int, Int)),
  current_time: Int,
) -> List(List(#(Int, Int)))
pub fn sort_by_f_score(
  positions: List(#(Int, Int)),
  f_score: Dict(#(Int, Int), Float),
) -> List(#(Int, Int))
pub fn stringify_space(tile: MemorySpace) -> String
Search Document