Documentation ¶
Index ¶
- Constants
- func Binomial(n, k int, primes []int) (result map[int]int, err error)
- func Combinations(n, k byte, f func(...interface{}) bool, args ...interface{}) (combinations [][]byte, retValue bool)
- func CompareBigInts(l, r BigInt) int
- func CompareFactors(f1, f2 map[int]int) bool
- func DecryptString(encryptedText string, gcm cipher.AEAD) (text string, err error)
- func EncryptString(txt string, gcm cipher.AEAD) (encryptedText string, err error)
- func Factorial(n int, primes []int) (factors map[int]int, err error)
- func Factorize(num int, primes []int) (factors map[int]int, err error)
- func FileToStrings(fileName string) (textLines []string, err error)
- func FindDivisors(factors map[int]int) (divisors []int)
- func FuncForTesting(expectedEncryptedString string, f funcToTest, args ...interface{}) (err error)
- func GCD(m, n int64) int64
- func GenerateGcm() (gcm cipher.AEAD, err error)
- func IsHexagonal(x int, roots map[int]int) bool
- func IsPentagonal(x int, roots map[int]int) bool
- func IsPrime(x int64) bool
- func IsTriangular(x int, roots map[int]int) bool
- func ModuloMultiply(a, b int64, mod int64) (result int64)
- func ModuloSelfPower(x int, mod int64) (selfPower int64)
- func ModuloSum(a, b int64, mod int64) (sum int64)
- func MulBigIntVectors(a, b *BigIntVector) (result *big.Int)
- func MultiplyFactors(primeFactors map[int]int) int64
- func NumDividedByTotient(n int, primes []int) float64
- func NumberFromDigits(digits []byte) (value int)
- func Permutations(limit byte, f func(...interface{}) bool, args ...interface{}) (permutations [][]byte)
- func PrimeSet(limit int) (primes []int, primeSet map[int]struct{})
- func Primes(limit int, f func(...interface{}) bool, args ...interface{}) (primes []int)
- func PrintMatrix(m [][]int)
- func ReverseSquares(limit int) (roots map[int]int)
- func Timed(f func(...interface{}) (string, error), args ...interface{})
- func Totient(n int, primes []int) int
- type BigInt
- func (bi *BigInt) AddTo(rhs BigInt)
- func (bi BigInt) Clone() (result *BigInt)
- func (bi *BigInt) Concatenate(rhs BigInt)
- func (bi BigInt) DigitCount() int
- func (bi BigInt) DigitSum() int
- func (bi BigInt) Digits() []byte
- func (bi BigInt) Int() int64
- func (bi BigInt) IsPalindrome() bool
- func (bi *BigInt) MulPowTen(pow int)
- func (bi *BigInt) MultiplyByDigit(d byte)
- func (bi *BigInt) PowBigInt(pow int)
- func (bi *BigInt) ReverseDigits()
- func (bi BigInt) SquareRoot(decimalCount int) (root BigInt, decimalIndex int)
- func (bi BigInt) String() string
- func (bi *BigInt) Subtract(rhs BigInt)
- type BigIntFraction
- type BigIntMatrix
- type BigIntVector
- type ChakravalaTriplet
- type ConcurrentStringSet
- type ContinuedFraction
- type DigitalNumber
- func (dn DigitalNumber) DifferentDigitCompositions(usedDigits map[byte]struct{}) (differentDigits bool)
- func (dn DigitalNumber) DifferentDigits() bool
- func (dn DigitalNumber) DigitCount() int
- func (dn DigitalNumber) DigitOccurencies() (occurencies map[byte]int)
- func (dn DigitalNumber) Digits() []byte
- func (dn DigitalNumber) NonZeroDigits() bool
- func (dn DigitalNumber) ReplaceDigits(replacements map[byte]byte) (value int)
- func (dn DigitalNumber) SameDigitSet(d2 DigitalNumber) bool
- func (dn DigitalNumber) X() int
- type FibonacciBox
- type FibonacciBoxTernaryTree
- type Fraction
- type Oker
- type OneResultSolver
- type PythagoreanTriplet
- type RootIntElement
Constants ¶
const ( // RecursiveKind is self-explanatory, you stupid Lint RecursiveKind = iota // ConcurrentKind is self-explanatory, you stupid Lint ConcurrentKind )
Variables ¶
This section is empty.
Functions ¶
func Combinations ¶
func Combinations(n, k byte, f func(...interface{}) bool, args ...interface{}) ( combinations [][]byte, retValue bool)
Combinations calculates and returns combinations of k out of n elements, or until f returns true. n has to be greater or equal to k. Each slice in the resulting combination matrix has 1s per elements used in a particular combination.
func CompareBigInts ¶
CompareBigInts returns -1, 0, 1 for l < r, l == r, l > r respectively
func CompareFactors ¶
CompareFactors comapares factors of two numbers returning true if equal
func DecryptString ¶
DecryptString decrypts
func EncryptString ¶
EncryptString encrypts
func Factorize ¶
Factorize returns prime factorization of num. Returns error if primes doesn't contain all prime factors of num
func FileToStrings ¶
FileToStrings reads the entire file and returns its lines in slice of strings
func FindDivisors ¶
FindDivisors takes factors map and returns slice of divisors
func FuncForTesting ¶
FuncForTesting is generic integration test function
func IsHexagonal ¶
IsHexagonal returns if x is hexagonal
func IsPentagonal ¶
IsPentagonal returns if x is pentagonal
func IsTriangular ¶
IsTriangular returns if x is triangular
func ModuloMultiply ¶
ModuloMultiply calculates multiplication module mod
func ModuloSelfPower ¶
ModuloSelfPower calculates self power of x module mod
func MulBigIntVectors ¶
func MulBigIntVectors(a, b *BigIntVector) (result *big.Int)
MulBigIntVectors multiplies arguments and puts the result in the new big.Int
func MultiplyFactors ¶
MultiplyFactors multiplies factors
func NumDividedByTotient ¶
func NumberFromDigits ¶
NumberFromDigits calculates number from its reversed digits
func Permutations ¶
func Permutations(limit byte, f func(...interface{}) bool, args ...interface{}) (permutations [][]byte)
Permutations calculates and returns permutations of limit elements, or until f returns true
func PrimeSet ¶
PrimeSet calculates and returns slice of primes less than limit and puts them in primeSet
func Primes ¶
Primes calculates and returns slice of primes smaller than limit, or until f returns true
func ReverseSquares ¶
ReverseSquares calculates and returns a map of squares to roots for roots less than limit
Types ¶
type BigInt ¶
type BigInt struct {
// contains filtered or unexported fields
}
BigInt is a struct holding slice of digits in reversed order
func MakeBigInt ¶
MakeBigInt constructs BigInt out of string
func MakeBigIntFromInt ¶
MakeBigIntFromInt constructs BigInt out of int
func MulBigInts ¶
MulBigInts multiplies BigInts
func (*BigInt) Concatenate ¶
Concatenate appends rhs digits to bi
func (BigInt) Int ¶
Int returns int64 value of bi. If bi respresents too big number, int64 will overflow.
func (BigInt) IsPalindrome ¶
IsPalindrome returns true iff bi is a palindrome
func (*BigInt) MultiplyByDigit ¶
func (*BigInt) ReverseDigits ¶
func (bi *BigInt) ReverseDigits()
ReverseDigits reverses digits of bi
func (BigInt) SquareRoot ¶
type BigIntFraction ¶
type BigIntFraction struct {
// contains filtered or unexported fields
}
BigIntFraction struct
func CalcElements ¶
func CalcElements(elements []*RootIntElement) BigIntFraction
CalcElements calculates and returns BigIntFraction value of the continued fraction represented by elements
func MakeFraction ¶
func MakeFraction(numerator, denominator *big.Int) (fr BigIntFraction)
MakeFraction creates and returns fr
func (BigIntFraction) Denominator ¶
func (fr BigIntFraction) Denominator() *big.Int
Denominator returns receiver's denominator
func (*BigIntFraction) Invert ¶
func (fr *BigIntFraction) Invert()
Invert flips receiver's numerator and denominator
func (BigIntFraction) Numerator ¶
func (fr BigIntFraction) Numerator() *big.Int
Numerator returns receiver's numerator
type BigIntMatrix ¶
type BigIntMatrix struct {
// contains filtered or unexported fields
}
BigIntMatrix struct
func MulBigIntMatrix ¶
func MulBigIntMatrix(a, b *BigIntMatrix) (result *BigIntMatrix)
MulBigIntMatrix multiplies arguments and puts the result in the new BigIntMatrix
func NewBigIntMatrix ¶
func NewBigIntMatrix(x, y int, m []int64) (result *BigIntMatrix, err error)
NewBigIntMatrix constructs new BigIntMatrix
func NewUnitBigIntMatrix ¶
func NewUnitBigIntMatrix(x int) (result *BigIntMatrix, err error)
NewUnitBigIntMatrix constructs new unit BigIntMatrix
func (*BigIntMatrix) At ¶
func (a *BigIntMatrix) At(y, x int) (result *big.Int, err error)
At returns element at (y,x)
func (*BigIntMatrix) Clone ¶
func (a *BigIntMatrix) Clone() (result *BigIntMatrix)
Clone copies receiver to new BigIntMatrix
func (*BigIntMatrix) Dim ¶
func (a *BigIntMatrix) Dim() (x, y int)
Dim returns length of the BigIntMatrix
type BigIntVector ¶
type BigIntVector struct {
// contains filtered or unexported fields
}
BigIntVector struct
func NewBigIntVector ¶
func NewBigIntVector(vec []int64) (result *BigIntVector, err error)
NewBigIntVector constructs new BigIntVector from slice of int64
func NewVectorFromBigIntSlice ¶
func NewVectorFromBigIntSlice(vec []*big.Int) (result *BigIntVector, err error)
NewVectorFromBigIntSlice constructs new BigIntVector from slice of *big.Int
func (*BigIntVector) Clone ¶
func (a *BigIntVector) Clone() (result *BigIntVector)
Clone copies receiver to new BigIntVector
type ChakravalaTriplet ¶
ChakravalaTriplet holds X, Y, K which are solution to X^2 - N*Y^2 = K
func Chakravala ¶
func Chakravala(n int) ChakravalaTriplet
Chakravala returns minimal solution to X^2 - N*Y^2 = 1. It uses Chakravala method, commonly attributed to Bhāskara II, a 12th century mathematician. His work was building on earlier works by Jayadeva (10th century) and Brahmagupta (7th century). Quality and mathematical depth of works by Indian mathematicians regarding numbers and algebra in general were only reached by European mathematicians much, much later
func Samasa ¶
func Samasa(n int, m *big.Int, prev ChakravalaTriplet) ChakravalaTriplet
func (ChakravalaTriplet) String ¶
func (c ChakravalaTriplet) String() string
type ConcurrentStringSet ¶
type ConcurrentStringSet struct {
// contains filtered or unexported fields
}
func NewConcurrentStringSet ¶
func NewConcurrentStringSet() ConcurrentStringSet
func (*ConcurrentStringSet) Read ¶
func (css *ConcurrentStringSet) Read() []string
func (*ConcurrentStringSet) Write ¶
func (css *ConcurrentStringSet) Write(s string)
type ContinuedFraction ¶
type ContinuedFraction struct { RootFloor int Head RootIntElement Fractions []RootIntElement // contains filtered or unexported fields }
ContinuedFraction holds
func MakeContinuedFraction ¶
func MakeContinuedFraction(x int, primes []int) (c ContinuedFraction)
MakeContinuedFraction creates and returns c, a continued fraction representation of sqrt(x). primes is a slice containing primes. It is necessary for gcd calculations important for reducing fractions
func (ContinuedFraction) Convergent ¶
func (c ContinuedFraction) Convergent(elementCount int) BigIntFraction
Convergent calculates BigIntFraction value of elementCount convergent
func (ContinuedFraction) Period ¶
func (c ContinuedFraction) Period() int
Period returns a period of receiver
func (ContinuedFraction) String ¶
func (c ContinuedFraction) String() string
String returns concise receiver's string representation
type DigitalNumber ¶
type DigitalNumber struct {
// contains filtered or unexported fields
}
DigitalNumber is immutable structure containing number and it's digits
func NewDigitalNumber ¶
func NewDigitalNumber(x int) (newDn DigitalNumber)
NewDigitalNumber constructs new DigitalNumber
func (DigitalNumber) DifferentDigitCompositions ¶
func (dn DigitalNumber) DifferentDigitCompositions(usedDigits map[byte]struct{}) (differentDigits bool)
DifferentDigitCompositions returns true iff DigitalNumber's digits are not in the set, and adds them to it if so. Caller is responsible for making the set
func (DigitalNumber) DifferentDigits ¶
func (dn DigitalNumber) DifferentDigits() bool
DifferentDigits returns true iff digits are different among themselves
func (DigitalNumber) DigitCount ¶
func (dn DigitalNumber) DigitCount() int
DigitCount returns number of digits
func (DigitalNumber) DigitOccurencies ¶
func (dn DigitalNumber) DigitOccurencies() (occurencies map[byte]int)
DigitOccurencies returns the map of digit occurencies
func (DigitalNumber) Digits ¶
func (dn DigitalNumber) Digits() []byte
Digits returns digits (reference)
func (DigitalNumber) NonZeroDigits ¶
func (dn DigitalNumber) NonZeroDigits() bool
NonZeroDigits returns true iff digits don't contain zero
func (DigitalNumber) ReplaceDigits ¶
func (dn DigitalNumber) ReplaceDigits(replacements map[byte]byte) (value int)
ReplaceDigits replaces digits in a number with ones from the map (index->new digit)
func (DigitalNumber) SameDigitSet ¶
func (dn DigitalNumber) SameDigitSet(d2 DigitalNumber) bool
SameDigitSet returns true iff d2 has the same multiset of digits as dn
type FibonacciBox ¶
type FibonacciBox struct {
A, B, C, D int
}
FibonacciBox is a representation of matrix | A B |
| C D |,
where A, B are coprime, and B, A, C, D is a generalized Fibonacci sequence, i.e. C = B + A, D = C +A. That implies the box can be generated from 2 numbers. Every box singularily represents a Pythagorean triplet: At = 2AC, Bt = BD, Ct = BC + AD
func (FibonacciBox) Triplet ¶
func (box FibonacciBox) Triplet() PythagoreanTriplet
type FibonacciBoxTernaryTree ¶
type FibonacciBoxTernaryTree struct { Root *FibonacciBox Child1 *FibonacciBoxTernaryTree Child2 *FibonacciBoxTernaryTree Child3 *FibonacciBoxTernaryTree }
func NewFibonacciBoxTernaryTree ¶
func NewFibonacciBoxTernaryTree(a, b, c, d int) FibonacciBoxTernaryTree
func (*FibonacciBoxTernaryTree) Generate ¶
func (tree *FibonacciBoxTernaryTree) Generate(limit int)
func (*FibonacciBoxTernaryTree) TripletSlice ¶
func (tree *FibonacciBoxTernaryTree) TripletSlice() []PythagoreanTriplet
type Fraction ¶
func NewFraction ¶
type OneResultSolver ¶
type OneResultSolver interface {
OneResultSolve(jobs <-chan interface{}) (interface{}, error)
}
OneResultSolver has OneResultSolve(jobs <-chan interface{}) (interface{}, error)
func OneResultSolverFactory ¶
func OneResultSolverFactory(kind int, f workerFunctionType) OneResultSolver
OneResultSolverFactory produces OneResultSolver appropriate per kind
type PythagoreanTriplet ¶
type PythagoreanTriplet struct {
A, B, C int
}
PythagoreanTriplet represents triplet for which A^2 + B^2 = C^2
func (PythagoreanTriplet) Length ¶
func (triplet PythagoreanTriplet) Length() int
func (PythagoreanTriplet) Multiply ¶
func (triplet PythagoreanTriplet) Multiply(k int) PythagoreanTriplet
func (PythagoreanTriplet) String ¶
func (triplet PythagoreanTriplet) String() string
type RootIntElement ¶
type RootIntElement struct { Head int64 Fractions rootIntFraction }
RootIntElement holds Head (integer part) and Fractions, rootIntFraction
Source Files ¶
- bigInt.go
- bigIntFraction.go
- bigIntMatrix.go
- bigIntVector.go
- chakravala.go
- ciphers.go
- combinations.go
- concurrentStringSet.go
- continuedFraction.go
- digitalNumber.go
- factorial.go
- factorization.go
- files.go
- fractions.go
- intMatrix.go
- moduloArithmetics.go
- oker.go
- oneResultSolver.go
- pentagonal.go
- permutations.go
- primes.go
- pythagoreanTriplet.go
- recursiveOneResult.go
- roots.go
- timed.go
- totient.go
- workerPoolOneResult.go