aoc

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: MIT Imports: 9 Imported by: 2

README

AoC golang utilities

This package provides both a CLI tool to generate a default AoC project, and a library to ease the solution writing.

Generating an AoC project

Installation
$ go install github.com/erdnaxeli/adventofcode/aoc/cmd/aoc@latest
Creating a new project
$ mkdir adventofcode2023
$ aoc github.com/<username>/adventofcode2023

This command will generate the boilerplate for a project in the current directory. It generates the following files:

  • main.go: a main() function with all the wiring to run the project
  • day01.go: the solutions for the day 1:
    • func day1p1(input Input) string: the solution for the part 1 of the day 1
    • func day1p2(input Input) string: the solution for the part 2 of the day 1
  • and similar files for all the other days
Usage

To use your project, you have to implement the solution in the corresponding file, then you run it like this:

$ # firt export your adventofcode.com session cookie
$ export AOC_SESSION=...
$ # then run your solution
$ go build
$ ./adventofcode2023 1 1  # run the solution for the part 1 of the day 1

The aoc library

This library provides many types, the two most important are:

  • Runner: the code that will get your puzzle input, run your solution, and submit the result. You should not have to deal with it as the CLI utility create a main.go file with everything set up.
  • Input: represent your puzzle input.

The Runner object wants a type implementing the Solver interface. This interface defines methods dayXpY() for each day and each part.

Every method dayXpY() takes a single parameter input Input which is the puzzle input. The type Input provides many method to parse the input. See the type documentation for more details.

Every method must return a single string. If the string is empty, the Runner assumes the solution is not implemented.

Have fun!

Documentation

Index

Constants

View Source
const URL = "https://adventofcode.com"

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	GetInput(year int, day int, part int) string
}

type Client

type Client interface {
	GetInput(year int, day int, part int) Input
	SendSolution(year int, day int, part int, solution string) error
}

type DefaultCache

type DefaultCache struct{}

func NewDefaultCache

func NewDefaultCache() DefaultCache

func (DefaultCache) GetInput

func (c DefaultCache) GetInput(year int, day int, part int) string

type DefaultClient

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

func NewDefaultClient

func NewDefaultClient(session string) (DefaultClient, error)

func (DefaultClient) GetInput

func (c DefaultClient) GetInput(year int, day int, part int) Input

func (DefaultClient) SendSolution

func (c DefaultClient) SendSolution(year int, day int, part int, solution string) error

type Input

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

func NewInput

func NewInput(content string) Input

func (Input) Content

func (i Input) Content() string

func (Input) ToIntSlice

func (i Input) ToIntSlice() []int

func (Input) ToStringSlice

func (i Input) ToStringSlice() []string

type Runner

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

func NewDefaultRunner

func NewDefaultRunner(year int, solver Solver) Runner

Return a new Runner object with default cache and client.

This is the main constructor you should use.

func NewRunner

func NewRunner(year int, client Client, solver Solver) Runner

Return a new Runner.

Unless you want to inject specific implementation for the cache and the client you should use NewDefaultRunner.

func (Runner) Run

func (r Runner) Run(day int, part int)

Run runs the solution for a given day and part

func (Runner) RunCli

func (r Runner) RunCli()

RunCli runs the solution for a given day and part.

It reads the day and the part for the executable arguments. The first argument is the day, the second is the part.

type Solver

type Solver interface {
	Day1p1(Input) string
	Day1p2(Input) string
	Day2p1(Input) string
	Day2p2(Input) string
	Day3p1(Input) string
	Day3p2(Input) string
	Day4p1(Input) string
	Day4p2(Input) string
	Day5p1(Input) string
	Day5p2(Input) string
	Day6p1(Input) string
	Day6p2(Input) string
	Day7p1(Input) string
	Day7p2(Input) string
	Day8p1(Input) string
	Day8p2(Input) string
	Day9p1(Input) string
	Day9p2(Input) string
	Day10p1(Input) string
	Day10p2(Input) string
	Day11p1(Input) string
	Day11p2(Input) string
	Day12p1(Input) string
	Day12p2(Input) string
	Day13p1(Input) string
	Day13p2(Input) string
	Day14p1(Input) string
	Day14p2(Input) string
	Day15p1(Input) string
	Day15p2(Input) string
	Day16p1(Input) string
	Day16p2(Input) string
	Day17p1(Input) string
	Day17p2(Input) string
	Day18p1(Input) string
	Day18p2(Input) string
	Day19p1(Input) string
	Day19p2(Input) string
	Day20p1(Input) string
	Day20p2(Input) string
	Day21p1(Input) string
	Day21p2(Input) string
	Day22p1(Input) string
	Day22p2(Input) string
	Day23p1(Input) string
	Day23p2(Input) string
	Day24p1(Input) string
	Day24p2(Input) string
	Day25p1(Input) string
	Day25p2(Input) string
}

An object implementing the solutions for all days.

A day method receives an Input object, and must return a string. If a day method returns an empty string, it will consider the solution is not implemented yet and it will not send it.

Directories

Path Synopsis
cmd
aoc command

Jump to

Keyboard shortcuts

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