utils

package
v0.0.0-...-74d6347 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 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, message string)

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

func Combinations

func Combinations(n int, m int) <-chan []int

Creates a channel that returns combinations of the first n integers in groups of length m. To be used as indices for combinations of slices.

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 Permutations

func Permutations(n int) <-chan []int

Permutations of n integers, to be used as index for slice permutations. Uses Heap's Algorithm (thanks wikipedia)

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) 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