utils

package module
v0.0.0-...-6f06159 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: GPL-3.0 Imports: 8 Imported by: 0

README

euler-utils-go

Golang Package of Utilities and Tools for Solving Project Euler Problems

Project Euler Official Site

There are no solutions here, only helper functions.

This is a work in progress, and is a personal interest project. What is written in here is made to create fast-running solutions. There are some things that could be organized better, or commented better, etc. If you find anything lacking, Pull Requests are welcome.

I am new to the Golang ecosphere, but am learning much, using Project Euler problems.

After doing several of the Euler problems, you find several standard functions are reused frequently.

This package has functions to generate Prime numbers, find Prime factors, Pandigital functions, GCD, Palindrome tests, Factorial, and more.

If you are working on Project Euler in Go, these will help you. In here you will find the raw materials with which to do these problems.

Dependencies

This package uses (https://github.com/yourbasic/bit) because it was blazing-fast.

TODO's

Testing

Tests should be done. I have not had a chance to write tests for these.

The tests so far are these functions get correct answers to the problems on Project Euler.

So far, I have completed over 50 of them.

Parallel Execution

Some of these might be optimized to use multiple CPU cores using goroutines and channels.

More Detailed Documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendNumbers

func AppendNumbers(first uint64, second uint64) uint64

AppendNumbers appends 2 numbers concat

func ArePandigitalCombined

func ArePandigitalCombined(a, b uint) bool

ArePandigitalCombined true if all three 1..9

func ArePandigitalTogether

func ArePandigitalTogether(numbers ...int) bool

ArePandigitalTogether true if all parameters together include exactly 1..9

func ArraySum

func ArraySum(array []int) int

ArraySum returns sum of all numbers in array

func BigPow

func BigPow(n int64, exp int64) *big.Int

BigPow raises n to exp TODO (Probably deprecated because of big.Int.Exp())

func DisplayElapsedTime

func DisplayElapsedTime(start time.Time)

DisplayElapsedTime displays time since start

func Factorial

func Factorial(number interface{}) (result int64)

Factorial int64 factorial

func FactorialFloat64

func FactorialFloat64(value float64) (result float64)

FactorialFloat64 float64 factorial

func FactorialUint64

func FactorialUint64(value uint64) (result uint64)

FactorialUint64 uint64 factorial

func Gcd

func Gcd(a, b uint64) uint64

Gcd finds greatest common divisor

func GeneratePrimes

func GeneratePrimes(limit int)

GeneratePrimes makes primes

func GetDigits

func GetDigits(source interface{}) (result []byte)

GetDigits returns digits

func GetDigitsASCII

func GetDigitsASCII(source interface{}) (result []byte)

GetDigitsASCII same as GetDigits but converts them all to ascii

func GetDivisors

func GetDivisors(number int) []int

GetDivisors creates a list of divisors for number

func GetPrimeFactors

func GetPrimeFactors(number interface{}) (int, *list.List)

GetPrimeFactors creates a list of Factor struct elements for number

func GetProperDivisors

func GetProperDivisors(number int) []int

GetProperDivisors creates a list/slice of properdivisors for number

func GetTruncations

func GetTruncations(n int) []int

GetTruncations returns array of all truncations of n, including n Ex 3797, 797, 97, 379, 37, 7, 3.

func IsPalindromicForBase

func IsPalindromicForBase(number uint64, base int) bool

IsPalindromicForBase returns true if number is palondromic in base

func IsPandigital

func IsPandigital(number interface{}, panMin, panMax int) bool

IsPandigital true if number has exactly 1 digit from panMin..panMax

func IsPentagonal

func IsPentagonal(number interface{}) bool

IsPentagonal true if is pentaganal

func IsPrime

func IsPrime(n uint64) bool

IsPrime is a fallback standard prime checker

func IsTriangularNumber

func IsTriangularNumber(v interface{}) bool

IsTriangularNumber bool optimized from comment in https://www.mathblog.dk/project-euler-42-triangle-words/

func LeftShifts

func LeftShifts(n uint64) []uint64

LeftShifts creates array of left shifts

func NthPermutationOfDigits

func NthPermutationOfDigits(number interface{}) (result string)

NthPermutationOfDigits makes //TODO: pass digits array in

func NumberDigits

func NumberDigits(n uint64) (result int)

NumberDigits calculates number digits

func Permutations

func Permutations(a []rune, f func([]rune))

Permutations calls f with each permutation of a.

func PythagoreanTripletsForPerimeter

func PythagoreanTripletsForPerimeter(p uint64) (*list.List, bool)

PythagoreanTripletsForPerimeter returns List of triplets

func ReverseString

func ReverseString(s string) string

ReverseString reverses s based on https://github.com/golang/example/blob/master/stringutil/reverse.go

func SwapBytesAt

func SwapBytesAt(s []byte, i, j int)

SwapBytesAt swaps at the indices

Types

type Factor

type Factor struct {
	Number   int64
	Exponent int
}

Factor for prime factorization

type PrimeGenerator

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

PrimeGenerator is for primes

func NewPrimeGenerator

func NewPrimeGenerator(limit int) *PrimeGenerator

NewPrimeGenerator makes a new one

func (*PrimeGenerator) IsPrime

func (generator *PrimeGenerator) IsPrime(value int) bool

IsPrime returns if value is prime

func (*PrimeGenerator) NextPrime

func (generator *PrimeGenerator) NextPrime(next int) int

NextPrime returns next prime

func (*PrimeGenerator) NumPrimes

func (generator *PrimeGenerator) NumPrimes() int

NumPrimes returns size

func (*PrimeGenerator) PrevPrime

func (generator *PrimeGenerator) PrevPrime(prev int) int

PrevPrime returns previous prime

type Primes

type Primes interface {
	IsPrime(value int) bool
	NextPrime() int
	PrimeFactors(number interface{}) (int, *list.List)
}

Primes means not divisible of course

type Triplet

type Triplet struct {
	A, B, C uint64
}

Triplet pythagorean triplet

Jump to

Keyboard shortcuts

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