Пример #1
0
func ncat(n []uint64) uint64 {
	var rd []uint64
	for i := len(n) - 1; i >= 0; i-- {
		rd = append(rd, euler.NtoD(n[i])...)
	}
	return euler.DtoN(rd)
}
Пример #2
0
func main() {
	var sum uint64
	digits := euler.NtoD(9876543210)
	firstprimes := []uint64{2, 3, 5, 7, 11, 13, 17}
	numperms := euler.Factorial(uint64(len(digits)))
search:
	for j := uint64(0); j < numperms; j++ {
		d := euler.NthPerm(j, digits)
		for i := range firstprimes {
			if euler.DtoN(d[i+1:i+4])%firstprimes[i] != 0 {
				continue search
			}
		}
		sum += euler.DtoN(d)
	}
	fmt.Printf("43 %d\n", sum)
}
Пример #3
0
func main() {
	var total uint64
	nf := euler.Factorial(9)
	uniq := make(map[uint64]bool)
	for i := uint64(0); i < nf; i++ {
		p := euler.NthPerm(i, []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9})
		for j := 1; j < 5; j++ {
			a, b, c := euler.DtoN(p[:j]), euler.DtoN(p[j:5]), euler.DtoN(p[5:])
			if a*b == c {
				uniq[c] = true
			}
		}
	}
	for i := range uniq {
		total += i
	}
	fmt.Printf("32 %d\n", total)
}
Пример #4
0
func main() {
	var count uint64
	var sum uint64
nextcandidate:
	for i := uint64(11); count < 11; i++ {
		d := euler.NtoD(i)
		dlen := len(d)
		for j := 0; j < len(d); j++ {
			a := euler.DtoN(d[j:dlen])
			b := euler.DtoN(d[0 : dlen-j])
			if !euler.IsPrime(a) || !euler.IsPrime(b) {
				continue nextcandidate
			}
		}
		count++
		sum += i
	}
	fmt.Printf("%d\n", sum)
}
Пример #5
0
func main() {
	var largest uint64
	digits := []uint64{1, 2, 3, 4, 5, 6, 7, 8, 9}
	for i := uint64(1); i <= 9; i++ {
		numperms := euler.Factorial(i)
		for j := uint64(0); j < numperms; j++ {
			dn := euler.NthPerm(j, digits[:i])
			n := euler.DtoN(dn)
			if euler.IsPrime(n) && pandigital(n) {
				if n > largest {
					largest = n
				}
			}
		}
	}
	fmt.Printf("41 %d\n", largest)
}
Пример #6
0
func rot(n uint64) (uint64, bool) {
	d := euler.NtoD(n)
	d = append(d[len(d):], d[:len(d)]...)
	return euler.DtoN(d), d[0] > 0
}