helpers

package module
v0.0.0-...-5ee2106 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package helpers provides helper functions for Advent of Code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Atoi

func Atoi(s string) int

Atoi is a wrapper around strconv.Atoi that calls log.Fatalf on error.

func AtoiSlice

func AtoiSlice(s []string) []int

AtoiSlice is a wrapper around Atoi that calls it for each string in the given slice. Deprecated: use Map(s, Atoi) instead.

func MakeRange

func MakeRange(start, end int) []int

MakeRange creates a slice containing integers from start to end inclusive. Returns an empty slice if start == end.

func Map

func Map[T, V any](slice []T, fn func(T) V) []V

Map applies the given function to each element in the given slice and returns a new slice with the results.

func ParseId

func ParseId(s string) int

ParseId parses a numerical id from a simple string, such as "Game 1" or "Card 2".

func Product

func Product(s []int) int

Product calculates the product of a slice of integers by multiplying all the elements together.

Types

type Scanner

type Scanner struct {
	*bufio.Scanner
	Close func() error
}

Scanner is a wrapper around bufio.Scanner that also has a Close method.

func NewScanner

func NewScanner(filepath string) *Scanner

NewScanner returns a new Scanner for the given filepath. If opening path fails log.Fatalf is called.

Jump to

Keyboard shortcuts

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