Пример #1
0
func Twins(a, b int) bool {
	a_ := int64(a)
	b_ := int64(b)
	if isPrime[mathutil.FromDigits(append(mathutil.ToDigits(a_, 10),
		mathutil.ToDigits(b_, 10)...), 10)] &&
		isPrime[mathutil.FromDigits(append(mathutil.ToDigits(b_, 10),
			mathutil.ToDigits(a_, 10)...), 10)] {
		return true
	}
	return false
}
Пример #2
0
func Next(n int64) int64 {
	factorialSum := int64(0)
	for _, digit := range mathutil.ToDigits(n, 10) {
		factorialSum += mathutil.Factorial(digit)
	}
	return factorialSum
}
Пример #3
0
// Return all the elements of the cartesian p-th power of Z_n
//
// For example, Z_3 = {0, 1, 2}, so (Z_3)**2 is the set of ordered pairs
// {  (0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)  }.
//
// The result has length n**power.
func CartesianPower(n int64, power int64) <-chan []int64 {
	if power == 0 {
		out := make(chan []int64, 0)
		close(out)
		return out
	}
	if n <= 0 {
		panic("n must be positive")
	}
	if power <= 0 {
		panic("power must be positive")
	}

	// Number of elements in the generated set
	cardinality := int64(math.Pow(float64(n), float64(power)))

	out := make(chan []int64)
	go func() {
		if n == 1 {
			out <- make([]int64, power)
		} else {
			for i := int64(0); i < cardinality; i = i + 1 {
				out <- sliceutil.ZeroPadLeftInt64(mathutil.ToDigits(i, n), power)
			}
		}
		close(out)
	}()
	return out
}
Пример #4
0
func ConcatenatedProduct(integer, n int64) int64 {
	digits := []int64{}
	for i := int64(1); i <= n; i++ {
		digits = append(digits, mathutil.ToDigits(integer*i, 10)...)
	}
	return mathutil.FromDigits(digits, 10)
}
Пример #5
0
func DigitSum(n int64) int64 {
	return sliceutil.SumInt64(mathutil.ToDigits(n, 10))
}
Пример #6
0
func C(a, b int64) bool {
	if isPrime[mathutil.FromDigits(append(mathutil.ToDigits(a, 10), mathutil.ToDigits(b, 10)...), 10)] && isPrime[mathutil.FromDigits(append(mathutil.ToDigits(b, 10), mathutil.ToDigits(a, 10)...), 10)] {
		return true
	}
	return false
}