day06_2019

package
v0.0.0-...-359cf57 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package day06_2019 contains the solver for Advent of Code - Day 6: Universal Orbit Map

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Edge

type Edge struct {
	Source      string
	Destination string
}

Edge represents an edge in a adj

type Graph

type Graph struct {
	// contains filtered or unexported fields
}

Graph represents a directed adj where the nodes are strings

func NewGraph

func NewGraph() Graph

NewGraph creates and initializes a new adj

func (*Graph) AddEdge

func (g *Graph) AddEdge(e Edge)

AddEdge adds an edge to the adj

func (*Graph) Neighbors

func (g *Graph) Neighbors(node string) []string

Neighbors returns a list of neighbors for a given node

func (*Graph) NodeExists

func (g *Graph) NodeExists(node string) bool

NodeExists tells if a node exists in the adj

func (*Graph) Nodes

func (g *Graph) Nodes() []string

Nodes returns the list of nodes the the adj

func (*Graph) Path

func (g *Graph) Path(startNode string, endNode string) []string

Path returns list of nodes in the path from startNode to endNode. The current implementation naively traverses the adj by only checking the first neighbor of each node. This is ok for the problem being solved, where we know the adj is a tree and we can safely assume there's always a direct path between start and end

func (*Graph) Reachable

func (g *Graph) Reachable(node string) int

Reachable returns how many nodes are reachable from a given one. The current implementation naively follows neighbors without checking for cycles. This is ok for the problem being solved, where we know we don't have cycles.

type Solver

type Solver struct {
	// Graph from COM to the other orbits. Intended to solve part 1.
	GraphFromCOM Graph
	// Graph from the other orbits to COM. Intended to solve part 2.
	GraphToCOM Graph
}

Solver implements the puzzle.Solver interface for the puzzle for day 6

func NewSolver

func NewSolver() *Solver

NewSolver returns a new solver

func (*Solver) Part1

func (s *Solver) Part1() (string, error)

Part1 solves part 1 of the puzzle. Required to implement Solver.

func (*Solver) Part2

func (s *Solver) Part2() (string, error)

Part2 solves part 2 of the puzzle. Required to implement Solver.

func (*Solver) ProcessInput

func (s *Solver) ProcessInput(fileContent string) error

ProcessInput processes the input by transforming into a list of wires. Required to implement Solver.

Jump to

Keyboard shortcuts

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