utils

package
v0.0.0-...-d15da94 Latest Latest
Warning

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

Go to latest
Published: May 1, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Directions = []Point{North, South, East, West}

Slice of cardinal directions

View Source
var East = Point{1, 0}

+X direction

View Source
var North = Point{0, 1}

+Y direction

View Source
var South = Point{0, -1}

-Y direction

View Source
var Verbose bool

Verbose flag. Use pflag.Parse() in main() to populate.

View Source
var West = Point{-1, 0}

-X direction

Functions

func Check

func Check(e error, format string, a ...any)

Check if error is not nil and panic with message if it is.

func CountBits

func CountBits(n uint32) int

Kernighan's Bit Counting Algorithm

func Gcd

func Gcd(a, b int64) int64

Greatest Common Denominator

func Lcm

func Lcm(a, b int64) int64

Least Common Multiple

func OCRLetters

func OCRLetters(message string) string

Convert Advent of Code height 6 font letters to a string. The message must be represented as 6 rows of # and . characters separated by newlines.

func ReadLines

func ReadLines(r io.Reader) []string

Read all lines from reader. Panic if there is an issue

Types

type Point

type Point struct {
	X int
	Y int
}

2-D Point

func (Point) Add

func (p Point) Add(p2 Point) Point

Return the sum of two points

func (Point) Left

func (p Point) Left() Point

Turn point left 90 degrees

func (Point) Manhattan

func (p Point) Manhattan() int

Return metropolis magnitude (abs(x)+abs(y))

func (Point) Right

func (p Point) Right() Point

Turn point right 90 degrees

func (Point) Scale

func (p Point) Scale(factor int) Point

Multiply point by a scalar

Jump to

Keyboard shortcuts

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