Exemplo n.º 1
0
func main() {
	digits := []uint64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	out := euler.NthPerm(999999, digits)
	fmt.Printf("24 ")
	for i := range out {
		fmt.Printf("%d", out[i])
	}
	fmt.Printf("\n")
}
Exemplo n.º 2
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)
}
Exemplo n.º 3
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)
}
Exemplo n.º 4
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)
}