day12

package
v0.0.0-...-d67b42a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ManhattanDistance

func ManhattanDistance(p Point, hill HillMap) int

Return the Manhattan distance to the end point

func Solve

func Solve(path string)

Types

type CostFunc

type CostFunc = func(Point, Point, HillMap) int

A cost function returns the cost of moving from one point to another

type ExpandFunc

type ExpandFunc = func(Point, HillMap) []Point

A expand function returns all neighbors of a point

type HeuristicFunc

type HeuristicFunc = func(Point, HillMap) int

A heuristic function returns an admissible estimate from one point to reach the end

type HillMap

type HillMap struct {
	Start  Point
	End    Point
	Height map[Point]int
}

A hill map has a start, end, and a point mapping to their heights

type Point

type Point struct {
	X int
	Y int
}

A point is represented by 2D coordinates

type Route

type Route struct {
	Path []Point
}

A Route includes a set of ordered points as Path

func AStar

func AStar(hill HillMap, expand ExpandFunc, cost CostFunc, heuristic HeuristicFunc) (Route, bool)

A* finds a path from start to goal.

hill is the map to be traversed, expand is an expansion function that returns all valid neighbors, cost is the cost function from point to another and the heuristic must be an admissible heuristic function in order to ensure the optimality of the results.

func BreadthFirstSearch

func BreadthFirstSearch(hill HillMap, expand ExpandFunc) (Route, bool)

Breadth-First Search traverse the map from the end to get to the first 'a'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL