chapter16

package
v0.0.0-...-45e99ae Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPatternMatchesBruteForce

func CheckPatternMatchesBruteForce(pattern, value string) bool

CheckPatternMatchesBruteForce checks if value matches pattern

func CheckPatternMatchesOptimized

func CheckPatternMatchesOptimized(pattern, value string) bool

CheckPatternMatchesOptimized checks if value matches pattern

func ConvertNumberToString

func ConvertNumberToString(num int) string

ConvertNumberToString converts an integer into it's string counterpart

func CountFactorialZeros

func CountFactorialZeros(num int) int

CountFactorialZeros counts the number of zeros in the factorial of num

func DivideWithOnlyAddition

func DivideWithOnlyAddition(x, y int) int

DivideWithOnlyAddition implements x/y

func FindSmallestNonNegativeDifference

func FindSmallestNonNegativeDifference(array1, array2 []int) int

FindSmallestNonNegativeDifference returns the smallest non negative difference of any 2 elements in both arrays

func FindUnsortedSequence

func FindUnsortedSequence(array []int) (left, right int)

FindUnsortedSequence returns the start and left of a sequence of elements in an array such that if those elements are sorted, then the array will be sorted.

func FlipSignWithAddition

func FlipSignWithAddition(num int) int

FlipSignWithAddition flips the sign of a number using only addition.

func GetContiguousSequence

func GetContiguousSequence(input []int) (sum int)

GetContiguousSequence returns the sum of largest sequence of elements in an input array

func GetContiguousSequenceBruteForce

func GetContiguousSequenceBruteForce(input []int) (sum int)

GetContiguousSequenceBruteForce returns the sum of the largest sequence of increasing elements from an array by testing all elements

func GetDivingBoardLengths

func GetDivingBoardLengths(number, shorter, longer int) []int

GetDivingBoardLengths gets the length that can be made up of 2 weights

func GetDivingBoardLoop

func GetDivingBoardLoop(number, shorter, longer int) []int

GetDivingBoardLoop gets the length using 1 loop.

func GetValidT9Words

func GetValidT9Words(number string, dictionary map[string]string) []string

GetValidT9Words returns words in dictionary having a t9 encoding

func GetWordFrequency

func GetWordFrequency(input string, word string) int

GetWordFrequency returns how many time a string exists in an input

func HasWonTicTacToe

func HasWonTicTacToe(board [3][3]int) int

HasWonTicTacToe checks if a tic tac toe board contains a winner

func LangtonsAnt

func LangtonsAnt(moves int) string

LangtonsAnt performs a simulation of the langtons ant.

func MaxAliveYear

func MaxAliveYear(people []person, min, _ int) int

MaxAliveYear gets the max year in which people are alive withing a certain range.

func MaxNumWithoutComparison

func MaxNumWithoutComparison(a, b int) int

MaxNumWithoutComparison gets the max of 2 numbers without comparing

func MultiplyWithOnlyAddition

func MultiplyWithOnlyAddition(x, y int) int

MultiplyWithOnlyAddition multiplies two numbers using only addition

func PairsWithSum

func PairsWithSum(array []int, sum int) (result [][]int)

PairsWithSum returns all pairs of numbers having a specific sum

func PondSizesBruteForce

func PondSizesBruteForce(plotOfLand [][]int) (sizes []int)

PondSizesBruteForce finds the length of all ponds in a matrix

func PondSizesOptimized

func PondSizesOptimized(land [][]int) (sizes []int)

PondSizesOptimized finds all ponds with a specified length

func Rand7

func Rand7() int

Rand7 generates a random number from 0-7

func SubtractWithOnlyAddition

func SubtractWithOnlyAddition(x, y int) int

SubtractWithOnlyAddition implements x - y

func SwapNumbersInPlace

func SwapNumbersInPlace(a, b *int)

SwapNumbersInPlace swaps 2 numbers without using any extra memory

func SwapNumbersInPlaceUsingBitOperations

func SwapNumbersInPlaceUsingBitOperations(a, b *int)

SwapNumbersInPlaceUsingBitOperations swaps 2 numbers using XOR operations

Types

type LRUCache

type LRUCache struct {
	// contains filtered or unexported fields
}

LRUCache is the data structure for an LRU cache

func NewLRUCache

func NewLRUCache(size int) *LRUCache

NewLRUCache creates a new LRU cache

func (*LRUCache) GetValue

func (cache *LRUCache) GetValue(key int) (val string, err error)

GetValue returns the value from the cache

func (*LRUCache) SetKeyValue

func (cache *LRUCache) SetKeyValue(key int, value string)

SetKeyValue sets the value into the front of the cache.

type MatrixPoint

type MatrixPoint struct {
	// contains filtered or unexported fields
}

MatrixPoint represents a point in a matrix

Jump to

Keyboard shortcuts

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