Beispiel #1
0
func Euler35() string {
	num := 0
	sieve := primes.FastSieve()
	circularPrimes := make(map[int]int)
	for a := <-sieve; a < 1000000; a = <-sieve {
		_, tested := circularPrimes[a]
		if tested {
			continue
		} else {
			//Test if it's circular
			circular := true
			primesTested := make(map[int]int)
			digits := []byte(strconv.Itoa(a))
			finishedRotations := false
			for ; ; arithmetics.Rotate(digits) {
				number, _ := strconv.Atoi(string(digits))
				_, finishedRotations = primesTested[number]
				if finishedRotations {
					break
				}
				primesTested[number] = 0
				if circular && !big.ProbablyPrime(big.NewInt(int64(number)), 1) {
					circular = false
				}
			}
			for n := range primesTested {
				if circular {
					num += 1
				}
				circularPrimes[n] = 0
			}
		}
	}
	return fmt.Sprint(num)
}
Beispiel #2
0
func Euler10() string {
	sum := 0
	for i := 0; i < 2000000; i = <-primes.FastSieve() {
		sum += i
	}
	return fmt.Sprint(sum)
}
Beispiel #3
0
func Euler37() string {
	sum := 0
	sieve := primes.FastSieve()
	count := 0
	primes := make(map[int]int)
	for prime := <-sieve; count < 11; prime = <-sieve {
		primes[prime] = prime
		if prime < 10 {
			continue
		}
		if isTruncable(prime, primes) {
			sum += prime
			count++
		}
	}
	return fmt.Sprint(sum)
}
Beispiel #4
0
func Euler46() string {
	sieve := primes.FastSieve()
	primes := make(map[int]int)
	for i := 0; i < 10000; i++ {
		prime := <-sieve
		primes[i] = prime
	}
	for compo := 9; ; compo += 2 {
		found := true
		for i := 0; i < compo; i++ {
			diff := compo - primes[i]
			if diff%2 == 0 && isSquare((diff)/2) {
				found = false
				break
			}
		}
		if found {
			return fmt.Sprint(compo)
		}
	}
	return "Problem occured"
}