Features | How does it work? | Getting started | Examples | Similar
NOTE: only supported on Linux, FreeBSD, and macOS due to the use of built-in plugin
package.
Run your Go Advent of Code solutions with a single command. Write your solution and Elver will take care of the rest.
- Automatically downloads and caches the input
- Runs your latest solution and times it
- Automatic benchmarking of your solution
- 0 third party dependencies
Elver uses plugin build mode to dynamically look up the solutions. These must reside in an Advent of Code folder under the main package.
$ go get github.com/aod/elver
Your https://adventofcode.com session token is required for downloading and caching the inputs.
Set your Advent of Code session token in the environment variable AOC_SESSION
.
Alternatively you can store it in the aoc_session
file in the
following directory:
- Linux:
$HOME/.config/elver/
- MacOS:
/Library/Application Support/elver/
- Windows:
%AppData%\elver\
A solution for a day in an Advent of Code year is represented by 2 solvers for part A and B.
All solvers are functions which satisfy the same signature where interface{}
is the output:
func (input string) (interface{}, error)
For the plugin build mode to work correctly all solvers must be exported. The name of a solver is also very important for elver to work properly. It's name must satisfy the following set of rules:
- Starts with
Day
- Followed by a valid Advent of Code day
- Within (inclusive) range of
1..25
- Within (inclusive) range of
- Ends with
A
for part 1 orB
for part 2.
Solvers are workspaced by the Advent of Code year which is also used as the folder name.
// /2015/01.go
package main
import "errors"
func Day1A(input string) (interface{}, error) {
return 42, nil
}
func Day1B(input string) (interface{}, error) {
return nil, errors.New("Not implemented")
}
Running Elver in the root directory will output something like the following:
$ elver
AOC 2015
Day 1 A (312ns):
42
Day 1 B (956ns):
[ERROR] Not implemented
Run Elver with the -b
flag to benchmark your latest solution:
$ elver -b
AOC 2015
Day 1 A (N=231919370, 5 ns/op, 0 bytes/op, 0 allocs/op):
42
Day 1 B (N=0, 0 ns/op, 0 bytes/op, 0 allocs/op):
[ERROR] Not implemented
Running the latest solvers:
$ elver
Running the latest solvers of a specific year:
$ elver -y 2017
Running the latest solvers of a specific day:
$ elver -d 21
Running the specific solvers of a year and day:
$ elver -y 2017 -d 21
Benchmarking the solvers by adding the -b
flag
$ elver -b
// Works with any combination of the previously mentioned flags e.g.:
$ elver -y 2017 -d 21 -b
These type of utility tools for Advent of Code also exist for other programming languages like cargo-aoc (Rust) and aocd (Python). Elver finds inspiration in these awesome projects so be sure to check them out as well!