util

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 4 Imported by: 1

README

Utility package

English -> Pig Latin Translation Rules

A word with no characters is unchanged.

  • If a word begins with a vowel sound, do not shift the letters. Note that "xr" and "yt" at the beginning of a word make vowel sounds (e.g. "xray" -> "xrayay", "yttria" -> "yttriaay"). Add 'way' to the end of the word.

  • If a word begins with a consonant sound, move it to the end of the word. Consonant sounds can be made up of multiple consonants, such as the "ch" in "chair" or "st" in "stand" (e.g. "chair" -> "airchay"). If a word starts with a consonant sound followed by "qu", also move the 'u' to the end of the word (e.g. "square" -> "aresquay"). Add 'ay' to the end of the word.

  • If a word contains a "y" after a consonant cluster or as the second letter in a two letter word the 'y' makes a vowel sound (e.g. "rhythm" -> "ythmrhay", "my" -> "ymay").

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convergent

func Convergent(n int, fn convergentSeries) (*big.Int, *big.Int)

Convergent returns the nth convegence of whichever series you pass in a function for.

func Cryptoquip

func Cryptoquip(w1, w2 string) (map[byte]byte, bool)

Cryptoquip returns whether the two strings have the same relative arrangement of letters. For instance, KEEP and LOOT.

func DigitSum

func DigitSum(n int) (sum int)

DigitSum returns the sum of the digits in the number.

func DigitsToInt

func DigitsToInt(digits []int) int

DigitsToInt converts a slice of digits to an int

func Divisors

func Divisors(n int) []int

Divisors returns a sorted list of all positive divisors of n

func E

func E(n int) int64

E returns the nth number (1-based) in the convergent series of the number e [2; 1,2,1, 1,4,1, 1,6,1, ... ,1,2k,1, ...]

func Equal

func Equal(a, b []int) bool

Equal returns true if the two slices have identical contents

func Factors

func Factors(n int) []int

Factors returns a sorted list of the unique prime factors of n (excluding n).

func FactorsCounted

func FactorsCounted(n int) map[int]int

FactorsCounted returns a map of prime factors of n with counts of how many times each factor divides into n.

func GCD added in v0.0.2

func GCD(a, b int) int

GCD returns the greatest common divisor of a and b

func Harshad

func Harshad(n, sum int) bool

Harshad returns true if n is divisible by the sum of its digits.

func IntToDigits

func IntToDigits(n int) []int

IntToDigits converts an int into a slice of its component digits

func IsAnagram

func IsAnagram(w1, w2 string) bool

IsAnagram returns true if w1 and w2 are anagrams of each other

func IsCube added in v0.0.4

func IsCube(n int) bool

IsCube returns true if n is a cube number

func IsInt added in v0.0.4

func IsInt(n float64) bool

IsInt returns true if n is an integer

func IsPalindromeInt

func IsPalindromeInt(p []int) bool

IsPalindromeInt returns true if the digits of p are a palindrome

func IsPalindromeString

func IsPalindromeString(p string) bool

IsPalindromeString returns true if the string is a palindrome

func IsSquare

func IsSquare(n int) bool

IsSquare returns true if n is a square number

func LCM added in v0.0.2

func LCM(a, b int) int

LCM returns the least common multiple of a and b

func MakeDigits

func MakeDigits(n int, c chan []int)

MakeDigits generates all permutations of the first n digits. For example:

n=2 [1 2] [2 1]
n=3 [1 2 3] [1 3 2] [2 1 3] [2 3 1] [3 1 2] [3 2 1]

func MulFraction added in v0.0.4

func MulFraction(n1, d1, n2, d2 int) (int, int)

MulFraction returns the product of the two fractions, still in fraction form

func PascalTriangle

func PascalTriangle(max int) [][]int

PascalTriangle returns a triangle of the max depth specified We build the triangle left-justified. A cell is the sum of the cell above it and the cell above and to the left.

1: 1
2: 1 1
3: 1 2 1
4: 1 3 3 1
5: 1 4 6 4 1

func ReduceFraction added in v0.0.4

func ReduceFraction(n, d int) (int, int)

func Reverse

func Reverse(digits []int) []int

Reverse reverses the order of the elements in a slice

func Sqrt2

func Sqrt2(n int) int64

Sqrt2 returns the nth number (1-based) in the convergent series of the square root of 2: [2;(2)]

func SquareFree

func SquareFree(n int) bool

SquareFree returns true if no square of a prime divides n

func SumFraction added in v0.0.2

func SumFraction(n1, d1, n2, d2 int) (int, int)

SumFraction returns the sum of the two fractions, still in fraction form

func Totient

func Totient(n int) int

Totient returns how many numbers k are relatively prime to n where 1 <= k < n. Relatively prime means that they have no common divisors (other than 1). 1 is considered relatively prime to all other numbers.

From https://www.doc.ic.ac.uk/~mrh/330tutor/ch05s02.html

The general formula to compute φ(n) is the following:

If the prime factorisation of n is given by n =p1e1*...*pnen, then φ(n) = n *(1 - 1/p1)* ... (1 - 1/pn).

For example:

9 = 32, φ(9) = 9* (1-1/3) = 6

4 =22, φ(4) = 4* (1-1/2) = 2

15 = 3*5, φ(15) = 15* (1-1/3)*(1-1/5) = 15*(2/3)*(4/5) =8

func Triangular

func Triangular(n int) bool

Triangular returns true if n is a trianglar number

Types

This section is empty.

Jump to

Keyboard shortcuts

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