util

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WordHundreds = []string{
		"zero",
		"one",
		"two",
		"three",
		"four",
		"five",
		"six",
		"seven",
		"eight",
		"nine",
		"ten",
		"eleven",
		"twelve",
		"thirteen",
		"fourteen",
		"fifteen",
		"sixteen",
		"seventeen",
		"eighteen",
		"nineteen",
	}
)

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 CtrlT

func CtrlT(str string, val *int, digits []int)

CtrlT prints a debugging message when SIGUSR1 is sent to this process.

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 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 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 f is a square

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 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 PigLatin

func PigLatin(s string) string

PigLatin returns the Pig Latin translation of a given word or sentence

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 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

func Wordify

func Wordify(n int) string

Wordify returns the words that represent n

Types

This section is empty.

Jump to

Keyboard shortcuts

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