Documentation ¶
Overview ¶
Package puzzle provides the interface for a puzzle solver and a function to run a solver. Also contains some utils. See the utils package for more details.
Index ¶
- func FetchAndSaveInput(session string, filePath string, year int, day int) (string, error)
- func FetchInput(session string, year int, day int) (string, error)
- func SaveInput(filePath string, input string) error
- func SubmitSolution(session string, year int, day int, part int, solution string) (string, error)
- type PerformanceMetrics
- type Solution
- type Solver
- type SolverRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FetchAndSaveInput ¶
FetchAndSaveInput fetches the input for a particular year and day of an Advent of Code puzzle and saves it to a file before returning it.
func FetchInput ¶
FetchInput gets an Advent of Code input directly from the site for a particular year and day. The session parameter must contain the value of the session cookie that will be used to perform the request.
Types ¶
type PerformanceMetrics ¶
type PerformanceMetrics struct { InputReadingTime time.Duration InputProcessingTime time.Duration Part1Time time.Duration Part2Time time.Duration }
PerformanceMetrics has performance metrics related to the execution of a puzzle
type Solution ¶
type Solution struct { // Part1Output is the output of part 1 as a string Part1Output string // Part2Output is the output of part 2 as a string Part2Output string }
Solution represents a solution for an Advent of Code puzzle. A solution includes the outputs for both parts of the puzzle
type Solver ¶
type Solver interface { // ProcessInput should process the input read from the file. // The argument is the whole contents of the file as a string. // It is up to the implementation how the result of the processing should be saved. // For Advent of Code, an instance variable that can be shared between part 1 and part 2 is often // a good way of saving the input processing. ProcessInput(fileContent string) error // Part1 should return the solution for part 1 of the puzzle Part1() (string, error) // Part1 should return the solution for part 2 of the puzzle Part2() (string, error) }
Solver is an Advent of Code puzzle solver.
type SolverRunner ¶
type SolverRunner struct { // Input contains a reader to the puzzle input Input io.Reader // Solver is the solver that can solve the puzzle Solver Solver // PerformanceMetrics contains stats about input reading/processing and the // execution of the solver PerformanceMetrics // Solution contains the output for both parts of the puzzle Solution }
SolverRunner runs a solver with the input coming from a reader. It runs the solver by executing solver.ProcessInput(), solver.Part1() and solver.Part2() sequentially.
func NewSolverRunnerFromFile ¶
func NewSolverRunnerFromFile(filepath string, solver Solver) (*SolverRunner, error)
NewSolverRunnerFromFile returns a new SolverRunner with the reader set to the contents of the file.
func (*SolverRunner) PrintSolutionAndStats ¶
func (sr *SolverRunner) PrintSolutionAndStats(w io.Writer) error
func (*SolverRunner) Run ¶
func (sr *SolverRunner) Run() (*Solution, error)
RunSolver takes a solver for a Puzzle and runs it, taking care of reading the input, processing it and running both parts. Also benchmarks the time for input processing and solving each part of the puzzle.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
2019/day01_2019
Package day01_2019 contains the solver for Advent of Code - Day 1: The Tyranny of the Rocket Equation
|
Package day01_2019 contains the solver for Advent of Code - Day 1: The Tyranny of the Rocket Equation |
2019/day02_2019
Package day02_2019 contains the solver for Advent of Code - Day 2: 1202 Program Alarm
|
Package day02_2019 contains the solver for Advent of Code - Day 2: 1202 Program Alarm |
2019/day03_2019
Package day03_2019 contains the solver for Advent of Code - Day 3: Crossed Wires
|
Package day03_2019 contains the solver for Advent of Code - Day 3: Crossed Wires |
2019/day04_2019
Package day04_2019 contains the solver for Advent of Code - Day 4: Secure Container
|
Package day04_2019 contains the solver for Advent of Code - Day 4: Secure Container |
2019/day05_2019
Package day05_2019 contains the solver for Advent of Code - Day 5: Sunny with a Chance of Asteroids
|
Package day05_2019 contains the solver for Advent of Code - Day 5: Sunny with a Chance of Asteroids |
2019/day06_2019
Package day06_2019 contains the solver for Advent of Code - Day 6: Universal Orbit Map
|
Package day06_2019 contains the solver for Advent of Code - Day 6: Universal Orbit Map |
2019/day07_2019
Package day07_2019 contains the solver for Advent of Code - Day 7: Amplification Circuit
|
Package day07_2019 contains the solver for Advent of Code - Day 7: Amplification Circuit |
2019/day08_2019
Package day08_2019 contains the solver for Advent of Code - Day 8: Space Image Format
|
Package day08_2019 contains the solver for Advent of Code - Day 8: Space Image Format |
2019/day09_2019
Package day09_2019 contains the solver for Advent of Code - Day 9: Sensor Boost
|
Package day09_2019 contains the solver for Advent of Code - Day 9: Sensor Boost |
2019/day10_2019
Package day10_2019 contains the solver for Day 10: Monitoring Station
|
Package day10_2019 contains the solver for Day 10: Monitoring Station |
Package utils contains some util functions and types for Advent Of Code.
|
Package utils contains some util functions and types for Advent Of Code. |