algos

package
v0.0.0-...-3c753f8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2024 License: Unlicense Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllGridOrientations

func AllGridOrientations(grid [][]string) [][][]string

AllGridOrientations returns the 8 possible orientations of a given grid i.e. rotated 4 times and the mirror image of all of those

func CaesarShift

func CaesarShift(in string, shiftAmount int) string

CaesarShift performs a forwards caesar shift of a given shiftAmount

func CombinationsInts

func CombinationsInts(nums []int, targetLength int) [][]int

CombinationsInts returns all combinations of an input slice of a given length

func MirrorStringGrid

func MirrorStringGrid(grid [][]string) (flipped [][]string)

MirrorStringGrid returns the grid mirrored over the y-axis (i.e. left to right)

func PermuteIntSlice

func PermuteIntSlice(numbers []int) [][]int

PermuteIntSlice will make all permutations of the numbers input

func PermuteString

func PermuteString(str string) []string

PermuteString generates all permutations for a given string

func PermuteStringSlice

func PermuteStringSlice(in []string) [][]string

PermuteStringSlice will make all permutations of a string slice

func RandomInt

func RandomInt(upper int) int

RandomInt returns a random int from zero through upper - 1

func RotateIntGrid

func RotateIntGrid(grid [][]int) [][]int

RotateGridInts will transpose a 2D array of ints

func RotateStringGrid

func RotateStringGrid(grid [][]string) [][]string

RotateGrid returns the inputted grid, rotated counterclockwise call it multiple times for 180, & 270 degree rotations

func SlidingWindowSum

func SlidingWindowSum(nums []int, targetSum int) (leftIndex, rightIndex int, found bool)

SlidingWindowSum returns the left and right indices of a window within the nums slice, where all numbers in the slice [left:right] sum up to targetSum It also returns a boolean indicating if a valid window is found

func SplitStringOn

func SplitStringOn(in string, cutset []string) []string

SplitStringOn is like strings.Split but takes in a slice of strings that are all used as dividers in the incoming string

func ThreeSum

func ThreeSum(nums []int, target int) (int, int, int, bool)

ThreeSum returns the three values within a slice that sum to the target input and a boolean stating if a match was found

func TwoSum

func TwoSum(nums []int, target int) (num1 int, num2 int, found bool)

TwoSum returns the two numbers found within a slice that add up to the input target, and a boolean to check if the sum is found or not

Types

This section is empty.

Jump to

Keyboard shortcuts

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