示例#1
0
文件: pr051.go 项目: d3zd3z/euler
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
}
示例#2
0
文件: pr049.go 项目: d3zd3z/euler
// 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
}