Exemplo n.º 1
0
func familySize(sieve *euler.Sieve, base, part int) (size int) {
	orig := euler.DigitsOf(base)
	work := make([]int, len(orig))
	size = 0

	found := false
	for _, d := range orig {
		if d == part {
			found = true
			break
		}
	}
	if !found {
		return
	}

	for value := part; value <= 9; value++ {
		copy(work, orig)
		for i := range orig {
			if work[i] == part {
				work[i] = value
			}
		}

		prime := euler.OfDigits(work)
		if sieve.IsPrime(prime) {
			size++
		}
	}
	return
}
Exemplo n.º 2
0
// Compute all of the digit permutations of the number.
func allPermutations(base int) (perms []int) {
	perms = make([]int, 1)
	perms[0] = base

	work := euler.DigitsOf(base)
	iwork := sort.IntSlice(work)
	for !euler.NextPermutation(iwork) {
		perms = append(perms, euler.OfDigits(work))
	}

	return
}