Exemplo n.º 1
0
Arquivo: p27.go Projeto: cven714/euler
func init() {
	prime := struct{}{}
	primes = make(map[int]struct{})

	for _, p := range utils.PrimesUpTo(10000) {
		primes[int(p)] = prime
	}
}
Exemplo n.º 2
0
Arquivo: p26.go Projeto: cven714/euler
func main() {
	// From wiki:
	//    A fraction in lowest terms with a prime denominator other than 2 or 5 (i.e. coprime to 10) always produces a repeating decimal.
	//    The period of the repeating decimal of 1/p is equal to the order of 10 modulo p

	var d uint64
	var maxPeriod int = 0

	// skipping 2, 3, 5
	for _, p := range utils.PrimesUpTo(1000)[3:] {
		period := order(10, p)
		if period > maxPeriod {
			maxPeriod, d = period, p
		}
	}

	fmt.Println(d)
}
Exemplo n.º 3
0
Arquivo: p41.go Projeto: cven714/euler
func init() {
	// Can skip 8/9 digit numbers as
	// 1 + .. + 9 = 45 => div by 3
	// 1 + .. + 8 = 35 => div by 3
	primes = utils.PrimesUpTo(7654321)
}
Exemplo n.º 4
0
Arquivo: p12.go Projeto: cven714/euler
func init() {
	primes = utils.PrimesUpTo(15000)
}
Exemplo n.º 5
0
Arquivo: p37.go Projeto: cven714/euler
The number 3797 has an interesting property. Being prime itself, it is possible to continuously remove digits from left to right, and remain prime at each stage: 3797, 797, 97, and 7. Similarly we can work from right to left: 3797, 379, 37, and 3.

Find the sum of the only eleven primes that are both truncatable from left to right and right to left.

NOTE: 2, 3, 5, and 7 are not considered to be truncatable primes.
*/

package main

import (
	"fmt"
	"strconv"
	"utils"
)

var primes []uint64 = utils.PrimesUpTo(1000000)
var present struct{} = struct{}{}
var primesMap map[uint64]struct{} = map[uint64]struct{}{
	2: present,
	3: present,
	5: present,
	7: present,
}

var truncatable map[uint64]struct{} = make(map[uint64]struct{})

func main() {
	// Start at the first prime > 10
	for i := 4; i < len(primes); i++ {
		p := primes[i]
		primesMap[p] = present