goaocd

package module
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2022 License: MIT Imports: 13 Imported by: 24

README

Go AoC Data

Set of utilities to load Advent of Code puzzle data and submit results

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CharMatrix added in v1.5.0

func CharMatrix(lookup *map[string]bool, args ...int) (int, int, *[][]string, *map[string]Pos)

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

func Chars(args ...int) []string

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

func DigitMatrix(args ...int) (int, int, *[][]uint8)

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

func Input(args ...int) string

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

func Integers(args ...int) []int

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

func Lines(args ...int) []string

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

func Submit(level int, answer interface{}, date ...int) bool

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

func NewPos(s string) Pos

Create new Pos from string of format XXX,YYY Example:

pos := NewPos("10,20")

func (*Pos) Eq added in v1.6.0

func (p *Pos) Eq(m Pos) bool

Check position is equals to another one

func (*Pos) ManhattanDist added in v1.6.0

func (p *Pos) ManhattanDist(to Pos) int

Calculate Manhattan distance between 2 positions

func (*Pos) Mut added in v1.6.0

func (p *Pos) Mut(m Pos) Pos

Create new position by applying mutation

Jump to

Keyboard shortcuts

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