Exemple #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)
}
Exemple #2
0
func pandigital(n uint64) bool {
	ndigits := euler.NtoD(n)
	var dc []int
	dc = make([]int, len(ndigits)+1)
	for i := range ndigits {
		d := euler.NtoD(ndigits[i])
		for j := range d {
			if d[j] == 0 || d[j] > uint64(len(ndigits)) {
				return false
			}
			dc[d[j]]++
		}
	}
	for i := 1; i <= len(ndigits); i++ {
		if dc[i] != 1 {
			return false
		}
	}
	return true
}
Exemple #3
0
func nthdigit(n uint64) uint64 {
	var size uint64 = 1
	var length uint64 = 1
	var digits uint64 = 1
	for n >= digits+9*size*length {
		digits += 9 * size * length
		size *= 10
		length++
	}
	number := size + ((n - digits) / length)
	position := (n - digits) % length
	return euler.NtoD(number)[length-1-position]
}
Exemple #4
0
func main() {
	var factmap [10]uint64
	var total uint64
	for i := uint64(1); i < 10; i++ {
		factmap[i] = euler.Factorial(i)
	}
	for i := uint64(3); i < 10000000; i++ {
		if i == sum(apply(euler.Factorial, euler.NtoD(i))) {
			total += i
		}
	}
	fmt.Printf("32 %d\n", total)
}
Exemple #5
0
func main() {
search:
	for i := uint64(1000); i < 10000-(3330*2); i++ {
		if i == 1487 {
			continue search
		}
		if !euler.IsPrime(i) {
			continue search
		}
		if !euler.IsPrime(i + 3330) {
			continue search
		}
		if !euler.IsPrime(i + 2*3330) {
			continue search
		}
		if !euler.IsPerm(euler.NtoD(i), euler.NtoD(i+3330)) {
			continue search
		}
		if !euler.IsPerm(euler.NtoD(i), euler.NtoD(i+3330*2)) {
			continue search
		}
		fmt.Printf("49 %d%d%d\n", i, i+3330, i+3330*2)
	}
}
Exemple #6
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)
}
Exemple #7
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)
}
Exemple #8
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
}