day01

package
v0.0.0-...-f4b2804 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NOT_A_NUMBER = regexp.MustCompile(`\D`)
View Source
var NUMBER = regexp.MustCompile(`\d`)
View Source
var STARTS_WITH_WORD_NUMBER = regexp.MustCompile(
	`^(one|two|three|four|five|six|seven|eight|nine|zero)`,
)

Functions

func EnhancedParseInput

func EnhancedParseInput(input string) ([]int, error)

EnhancedParseInput takes into account that the input may contain words that represent numbers into the parsing.

It returns a slice of ints.

func ParseInput

func ParseInput(input string) ([]int, error)

ParseInput takes a string and returns a slice of ints, ignoring any non-numeric characters.

A number will be added to the slice per line. The number will be the first and last digit of the line.

If the line has only one digit, it will be repeated twice.

func ParseNumber

func ParseNumber(input string) (int, error)

ParseNumber takes a string, which should be a number, and returns the first and last digit of the number.

If the number is only one digit, it will be repeated twice.

This function panics if the input is not a number.

func Tokenizer

func Tokenizer(
	data []byte,
	atEOF bool,
) (advance int, token []byte, err error)

tokenizer is a split function for a Scanner that will recognize numbers and words that represent numbers.

It returns each token as a byte slice and converts words to numbers before returning them.

If the token is not a number or a word, it will return the token as it is.

This function does not return an error.

Types

type Exercise

type Exercise struct{}

func (Exercise) Part1

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

func (Exercise) Part2

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

Jump to

Keyboard shortcuts

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