advent

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package advent contains all advent of code related functionality.

Index

Constants

View Source
const (
	StatusWidth  int = 4
	TaskWidth    int = 6
	ExtraPadding int = 6
	TimeWidth    int = 20

	HeaderWidth int = 40
)

Variables

View Source
var (
	ErrEmptyLanguage     = errors.New("no language specified")
	ErrNotFound          = afero.ErrFileNotFound
	ErrNotImplemented    = errors.New("not implemented")
	ErrNoRunner          = errors.New("no runner available")
	ErrInvalidData       = errors.New("invalid data")
	ErrNoImplementations = errors.New("no implementations found")
	ErrLoadInfo          = errors.New("load info")
)
View Source
var (
	ErrNotConfigured    = errors.New("not configured")
	ErrNilConfiguration = errors.New("nil configuration")
	ErrHTTPRequest      = errors.New("http request")
	ErrHTTPResponse     = errors.New("http response")
	ErrInvalidURL       = errors.New("invalid URL")
	ErrInvalidLanguage  = errors.New("invalid language")
)
View Source
var ErrRunnerStart = errors.New("runner start error")

Functions

func NormalizationFactor

func NormalizationFactor() float64

func ParseURL

func ParseURL(url string) (int, int, error)

func WithDir

func WithDir(dir string) func(*Exercise)

func WithDownloadLanguage

func WithDownloadLanguage(lang string) func(*Downloader)

WithDownloadLanguage sets the language for the exercise implementation. This will override any language set in the configuration.

func WithExerciseDir

func WithExerciseDir(dir string) func(*Benchmarker)

func WithInputFile

func WithInputFile(file string) func(*Exercise)

func WithLanguage

func WithLanguage(lang string) func(*Exercise)

func WithOverwrites

func WithOverwrites(o *Overwrites) func(*Downloader)

WithOverwrites sets the files that can be overwritten if already in place.

func WithSkipImpl

func WithSkipImpl(skip bool) func(*Downloader)

WithSkipImpl sets the downloader to skip creating implementation files and structure.

func WithURL

func WithURL(url string) func(*Downloader)

WithURL sets the exercise URL to download.

Types

type Answer

type Answer struct {
	One string `json:"a"`
	Two string `json:"b"`
}

Answer contains the answer for each part of an exercise.

type BenchmarkData

type BenchmarkData struct {
	Date time.Time `json:"run-date,omitempty"`
	// Dir             string                `json:"dir"`
	Title           string                `json:"title"`
	Year            int                   `json:"year,omitempty"`
	Day             int                   `json:"day"`
	Runs            int                   `json:"numRuns"`
	Normalization   float64               `json:"normalization,omitempty"`
	Implementations []*ImplementationData `json:"implementations"`
}

func (*BenchmarkData) String

func (b *BenchmarkData) String() string

type Benchmarker

type Benchmarker struct {
	*Exercise
	// contains filtered or unexported fields
}

func NewBenchmarker

func NewBenchmarker(config krampus.ExerciseConfiguration, options ...func(*Benchmarker)) (*Benchmarker, error)

func (*Benchmarker) Benchmark

func (b *Benchmarker) Benchmark(afs afero.Fs, iterations int) ([]tasks.Result, error)

type Data

type Data struct {
	InputData     string   `json:"-"`
	InputFileName string   `json:"inputFile"`
	TestCases     TestCase `json:"testCases"`
	Answers       Answer   `json:"answers,omitempty"`
}

Data contains the relative path to exercise input and the specific test case data for an exercise.

type Downloader

type Downloader struct {
	*Exercise
	// contains filtered or unexported fields
}

func NewDownloader

func NewDownloader(config krampus.DownloadConfiguration, options ...func(*Downloader)) (*Downloader, error)

func (*Downloader) Download

func (d *Downloader) Download() error

type Exercise

type Exercise struct {
	ID       string `json:"id"`
	Title    string `json:"title"`
	Language string `json:"-"`
	Year     int    `json:"year"`
	Day      int    `json:"day"`
	URL      string `json:"url"`
	Data     *Data  `json:"data"`
	Path     string `json:"-"`
	// contains filtered or unexported fields
}

func New

func New(config krampus.ExerciseConfiguration, options ...func(*Exercise)) (*Exercise, error)

func (*Exercise) Dir

func (e *Exercise) Dir() string

Dir returns the base of the exercise directory. It will return an empty string if the exercise does not exist.

Example: 01-someExerciseTitle.

func (*Exercise) GetImplementations

func (e *Exercise) GetImplementations() ([]string, error)

GetImplementations returns a list of available implementations for the exercise.

func (*Exercise) LogValue

func (e *Exercise) LogValue() slog.Value

func (*Exercise) Solve

func (e *Exercise) Solve(skipTests bool) ([]tasks.Result, error)

func (*Exercise) String

func (e *Exercise) String() string

func (*Exercise) Test

func (e *Exercise) Test() ([]tasks.Result, error)

type ImplementationData

type ImplementationData struct {
	Name    string    `json:"name"`
	PartOne *PartData `json:"part-one"`
	PartTwo *PartData `json:"part-two,omitempty"`
}

func (*ImplementationData) String

func (i *ImplementationData) String() string

type Overwrites

type Overwrites struct {
	Input bool
}

type PartData

type PartData struct {
	Mean float64   `json:"mean"`
	Min  float64   `json:"min"`
	Max  float64   `json:"max"`
	Data []float64 `json:"data,omitempty"`
}

type Test

type Test struct {
	Input    string `json:"input"`
	Expected string `json:"expected"`
}

Test contains the input and expected output for a test case.

type TestCase

type TestCase struct {
	One []*Test `json:"one"`
	Two []*Test `json:"two"`
}

TestCase contains the test case for each part of an exercise.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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