Documentation
¶
Overview ¶
GoAoCd - Set of utilities in Golang for loading Advent of Code puzzle data and submitting results
To authenticate on AoC server, your token is required. Store it in AOC_SESSION environment variable. You can place .env file in current directory and put token there, it will be automatically loaded.
Puzzle input is cached on disk. In current directory new folder .aocd_cache is created and puzzles are stored inside (divided by year and day).
Index ¶
- func CharMatrix(lookup *map[string]bool, args ...int) (int, int, *[][]string, *map[string]Pos)
- func Chars(args ...int) []string
- func DigitMatrix(args ...int) (int, int, *[][]uint8)
- func Duration(name string) func()
- func Input(args ...int) string
- func Integers(args ...int) []int
- func Lines(args ...int) []string
- func Submit(level int, answer interface{}, date ...int) bool
- type Pos
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CharMatrix ¶ added in v1.5.0
CharMatrix - matrix of chars Pass pointer map[string]bool as first argument to lookup specified chars (keys) in result matrix. Result lookup table will be returned in 4-th argument in form of map[string]Pos See Input() docs for more info on parameters, authentication and caching
Example Input:
S1 2E
Code:
var lookup = map[string]bool{"S": true, "E": true} width, height, mat, lookupResult := CharMatrix(&lookup) lookupResult["S"].X // -> 0 lookupResult["E"].Y // -> 1 mat[0][1] // -> "1"
func Chars ¶ added in v1.9.0
Returns puzzle as an array of letters (in form of strings, not runes or bytes) Input:
abcd
Code:
s := goaocd.Chars() s[0] // "a" s[1] // "b"
See Input() docs for more info on parameters, authentication and caching
func DigitMatrix ¶
DigitMatrix - return puzzle input as a matrix of uint8 Expect puzzle is multiple lines, divided by new line (\n) Each line contains digits without separator Also, width and height are returned. First dimension of matrix is y (rows), second is x (columns)
Input:
123 456
Code:
width, height, mat := aocd.DigitMatrix() fmt.Printf("Matrix %dx%d", width, height); fmt.Printf("mat[0][2]=%d", mat[0][2]);
Output:
Matrix 3x2 mat[0][2]=3
See Input() docs for more info on parameters, authentication and caching
func Duration ¶
func Duration(name string) func()
Duration is a helper to measure function run time. Invoke with a single parameter - name of a function. Function returns done callback. Use defer to invoke it on function finish.
done := Duration("Part A") defer done()
Output:
Part A duration: 2.16825ms
func Input ¶
Input - returns puzzle input as raw string. If called with no arguments, this helper will try to guess day from executale name. If executable is named like "day13" and goaocd.Input() is invoked, puzzle from day 13 of current year will be loaded, no matter which day is now actually. If guessing failed, current day is used
If called with one argument - year is current and day is value of an argument.
goaocd.Input(4) // Puzzle for day 4 of current year
If called with 2 arguments, first is year and second is day.
goaocd.Input(2021, 3) // Puzzle for day 3 of AoC'2021
func Integers ¶
Integers - return puzzle input as an array of integers Initial input is splitted by " " (space) character
See Input() docs for more info on parameters, authentication and caching
func Lines ¶
Lines - return puzzle input as an array of strings. Initial input is splitted by \n character
See Input() docs for more info on parameters, authentication and caching
func Submit ¶
Submit is used to... submit answers. Level must be 1 or 2 (will panic in other case). Answer can be string of number (%v used to format). 2 more arguments can be used to configure date and year of puzzle. See Input() docs for more info on how date configuration works.
Example:
Submit(1, 42) // Submit 42 as an answer to part A of current day and current year Submit(2, 100500, 12) // Submit 100500 as an answer to part B of day 12 of current year
Types ¶
type Pos ¶ added in v1.5.0
type Pos struct {
X, Y int
}
Position with coordinates X and Y
func NewPos ¶ added in v1.8.0
Create new Pos from string of format XXX,YYY Example:
pos := NewPos("10,20")
func (*Pos) ManhattanDist ¶ added in v1.6.0
Calculate Manhattan distance between 2 positions