day05

package
v0.0.0-...-cede9f0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidAlmanacHeader = errors.New("invalid almanac header")

ErrInvalidAlmanacHeader is returned when the almanac header is not correctly parsed

View Source
var ErrInvalidAlmanacRange = errors.New("invalid almanac range")

ErrInvalidAlmanacRange is returned when the almanac range is not valid

View Source
var ErrNotEnoughData = errors.New("no enought data to complete")

ErrNotEnoughData is returned when the input given does not have enough data to complete.

View Source
var ErrParse = errors.New("error while parsing")

ErrParse is returned when an error has happened during parsing

Functions

func ApplyFuncs

func ApplyFuncs(
	almanacEntries map[string]AlmanacEntry,
	seed int,
) int

func FindSeedPointsToTest

func FindSeedPointsToTest(
	srs []SeedRange,
	ae map[string]AlmanacEntry,
) []int

func ParseAlmanacLines

func ParseAlmanacLines(data string) (map[string]AlmanacEntry, error)

ParseAlmanacLines gets all the almanac lines and converts them into a map with the From acting as key, and a AlmanacEntry object as value. The AlmanacEntry contains information about the ranges in that entry, and the From and To values.

If an error occurs while parsing, it stops and returns the error.

func ParseSeedsLine

func ParseSeedsLine(line string) ([]int, error)

ParseSeedsLine parses a line of seeds and returns a slice of integers. It expects the line to start with the prefix "seeds:". If the line does not start with the prefix or is empty, it returns an empty slice. Each field in the line is parsed as an integer and added to the result slice. If any field fails to parse as an integer, it returns an error with the field and the parsing error.

Types

type AlmanacEntry

type AlmanacEntry struct {
	From   string
	To     string
	Mapper intmapper.IntMapper
}

AlamanacEntry represents an entry on the almanac

func NewAlamacEntry

func NewAlamacEntry(
	from string,
	to string,
) AlmanacEntry

NewAlamacEntry will return an almanac with an empty list of ranges

func ParseAlmanacEntry

func ParseAlmanacEntry(data string) (AlmanacEntry, error)

ParseAlmanacEntry gets an almanac entry, which is composed of a title and a list of ranges, and returns the right AlmanacEntry structure, with the Mapper initialized

type Exercise

type Exercise struct{}

func (Exercise) Part1

func (e Exercise) Part1(data string) (int, error)

func (Exercise) Part2

func (e Exercise) Part2(data string) (int, error)

type SeedRange

type SeedRange struct {
	Start int
	End   int
	Len   int
}

SeedRange contains information about a range of seeds. It can be used to create iterators over those ranges, without allocatiing the list of integers first (python range inspired).

func NewSeedRange

func NewSeedRange(start, length int) SeedRange

Returns a new initialized SeedRange

func ParseSeedLineAsRanges

func ParseSeedLineAsRanges(line string) ([]SeedRange, error)

ParseSeedLineAsRanges will parse the seeds line, but interpreting the line as a sequence of tuples, where the first element of the tuple specifies the start of the seed range, and the second the length of the range.

E.g. 10 5, will be seeds 10, 11, 12, 13, 14 and 15

Directories

Path Synopsis
intconv defines IntConversor structure which can be used to map integers between two ranges
intconv defines IntConversor structure which can be used to map integers between two ranges

Jump to

Keyboard shortcuts

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