Example #1
0
// Primes returns int64 slice of prime factors of n
func Primes(n int64) []int64 {
	p := []int64{}

	for _, v := range Divisors(n) {
		if isit.Prime(v) {
			p = append(p, v)
		}
	}

	return p
}
Example #2
0
// Primes returns a continuous channel of int64 Primes
func Primes() <-chan int64 {
	c := make(chan int64, 1)

	go func() {
		c <- 2

		for i := int64(3); i < int64(math.MaxInt64); i += 2 {
			if isit.Prime(i) {
				c <- i
			}
		}

		close(c)
	}()

	return c
}
Example #3
0
// PrimesFrom returns a channel of primes from start
func PrimesFrom(start int64) <-chan int64 {
	c := make(chan int64, 1)

	go func() {
		if start%2 == 0 {
			start++
		}

		for i := start; i < int64(math.MaxInt64); i++ {
			if isit.Prime(i) {
				c <- i
			}
		}
		close(c)
	}()

	return c
}
Example #4
0
// PrimesBetween returns a channel with all primes between start and finish
func PrimesBetween(start, finish int64) <-chan int64 {
	c := make(chan int64, 1)

	go func() {
		if start%2 == 0 {
			start++
		}

		for i := start; i < finish; i += 2 {
			if isit.Prime(i) {
				c <- i
			}
		}
		close(c)
	}()

	return c
}
Example #5
0
// NPrimesFrom returns n conescutive primes starting from x
func NPrimesFrom(x, n int64) <-chan int64 {
	c := make(chan int64, 1)

	go func() {
		if x%2 == 0 {
			x++
		}

		count := int64(0)
		for i := x; count < n; i += 2 {
			if isit.Prime(i) {
				c <- i
				count++
			}
		}

		close(c)
	}()

	return c
}