glue

package
v0.0.0-...-be83087 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package glue contains the glue code to link together the different days' solvers.

The expected way to use this package is:

  • Have your daily solver packages not export anything, but just have init functions that call this package's `RegisterFoo` functions.
  • For each year, have a `yNNNN` package that blank-imports each day to pull them in.
  • To build the standard omnibus binary, blank-import each year, and call `Main`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ints

func Ints(in ...int) (out []string)

Ints converts a list of ints to a list of strings.

func Main

func Main()

Main implements the main function for the combined AoC binary.

func RegisterPlotter

func RegisterPlotter(year, day int, suffix string, p Plotter, examples map[string]string)

RegisterPlotter makes a plotter known to the glue code as the nominated plotter of the given day.

func RegisterSolver

func RegisterSolver(year, day int, s Solver)

RegisterSolver makes a solver known to the glue code as the nominated solver of the given day. This function is expected to be called from an `init` func.

func RunBenchmarks

func RunBenchmarks(b *testing.B, testRoot string, year int)

func RunTests

func RunTests(t *testing.T, testRoot string, year int)

func Solve

func Solve(year, day int, input io.Reader) ([]string, error)

Solve solves the given AoC puzzle using the provided input.

func SolveFile

func SolveFile(year, day int, path string) ([]string, error)

SolveFile calls Solve on an input file.

func WithParser

func WithParser[PF ~func(I) (O, error), SF ~func([]O) ([]string, error), I, O any](pf PF, sf SF) func([]I) ([]string, error)

WithParser wraps a solver function with one that parses each item separately before it gets called.

Types

type ChunkPlotter

type ChunkPlotter func([]string, io.Writer) error

func (ChunkPlotter) Plot

func (p ChunkPlotter) Plot(r io.Reader, w io.Writer) error

Plot implements the Plotter interface.

type ChunkSolver

type ChunkSolver func([]string) ([]string, error)

ChunkSolver wraps a solution that wants the blank-line-separated paragraphs of the input as strings.

func (ChunkSolver) Solve

func (s ChunkSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type FixedLevelSolver

type FixedLevelSolver func(*util.FixedLevel) ([]string, error)

FixedLevelSolver wraps a solution that wants the lines of the input converted to the trimmed-down `util.FixedLevel` type.

func (FixedLevelSolver) Solve

func (s FixedLevelSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type GenericSolver

type GenericSolver func(io.Reader) ([]string, error)

GenericSolver wraps a solution function that does all the work itself.

func (GenericSolver) Solve

func (s GenericSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type IntSolver

type IntSolver func([]int) ([]string, error)

IntSolver wraps a solution that wants the input read in as a list of decimal integers. The separators can be any non-digit characters.

func (IntSolver) Solve

func (s IntSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type LevelSolver

type LevelSolver struct {
	Solver func(*util.Level) ([]string, error)
	Empty  byte
}

LevelSolver wraps a solution that wants the lines of the input converted to a 2D level structure.

func (LevelSolver) Solve

func (s LevelSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type LinePlotter

type LinePlotter func([]string, io.Writer) error

LinePlotter wraps a plotter that wants the lines of the input as strings.

func (LinePlotter) Plot

func (p LinePlotter) Plot(r io.Reader, w io.Writer) error

Plot implements the Plotter interface.

type LineSolver

type LineSolver func([]string) ([]string, error)

LineSolver wraps a solution that wants the lines of the input as strings.

func (LineSolver) Solve

func (s LineSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type Plotter

type Plotter interface {
	Plot(r io.Reader, w io.Writer) error
}

Plotter represents a function capable of turning an AoC puzzle input to a GraphViz dot graph.

type RegexpSolver

type RegexpSolver struct {
	Solver func([][]string) ([]string, error)
	Regexp string
}

RegexpSolver wraps a solution that wants to match a single regular expression to each of the input lines. The solver is called with a slice of slices of all submatches. Note that this excludes the full pattern match that is typically included in regexp match outputs.

func (RegexpSolver) Solve

func (s RegexpSolver) Solve(input io.Reader) ([]string, error)

Solve implements the Solver interface.

type Solver

type Solver interface {
	// Solves the puzzle by reading the given input, and producing a set of output lines.
	Solve(r io.Reader) ([]string, error)
}

Solver represents a function capable of solving one of the AoC puzzles.

type TestCase

type TestCase struct {
	Year      int
	Day       int
	InputFile string
	Want      []string
}

func FindAllTests

func FindAllTests(testRoot string) (tests []TestCase, err error)

func FindTests

func FindTests(testRoot string, year int) (tests []TestCase, err error)

type YearDay

type YearDay struct{ Year, Day int }

YearDay names an AoC puzzle by the event year (2015+) and puzzle day (1-25).

type YearDaySuffix

type YearDaySuffix struct {
	YearDay
	Suffix string
}

YearDaySuffix names a plotter by the event year (2015+), puzzle day (1-25) and an optional disambiguation suffix.

Jump to

Keyboard shortcuts

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