Documentation ¶
Index ¶
- Variables
- func ApplyFuncs(almanacEntries map[string]AlmanacEntry, seed int) int
- func FindSeedPointsToTest(srs []SeedRange, ae map[string]AlmanacEntry) []int
- func ParseAlmanacLines(data string) (map[string]AlmanacEntry, error)
- func ParseSeedsLine(line string) ([]int, error)
- type AlmanacEntry
- type Exercise
- type SeedRange
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidAlmanacHeader = errors.New("invalid almanac header")
ErrInvalidAlmanacHeader is returned when the almanac header is not correctly parsed
var ErrInvalidAlmanacRange = errors.New("invalid almanac range")
ErrInvalidAlmanacRange is returned when the almanac range is not valid
var ErrNotEnoughData = errors.New("no enought data to complete")
ErrNotEnoughData is returned when the input given does not have enough data to complete.
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 ¶
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 ¶
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 SeedRange ¶
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 ¶
Returns a new initialized SeedRange
func ParseSeedLineAsRanges ¶
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