Пример #1
0
func countSetsRecursively(lastLen, lastK int, current vector.StringVector, usedDigits map[int]bool,
	primes [][]map[int]bool, primesByLen [][]string) int64 {

	currentLength := len(usedDigits)

	if currentLength == 9 {
		//fmt.Println(current)
		return 1
	} else if currentLength > 9 {
		panic("w00t")
	}

	count := int64(0)

	for length, v := range primes {

		if currentLength+length > 9 {
			break
		}

		if length < lastLen {
			continue
		}

		for k, digits := range v {

			if k <= lastK {
				continue
			}

			joinedDigits := joinDigitMaps(usedDigits, digits)

			if len(joinedDigits) == currentLength+len(digits) {

				currentCopy := current.Copy()
				currentCopy.Push(primesByLen[length][k])

				count += countSetsRecursively(length, k, currentCopy, joinedDigits, primes, primesByLen)

			}

		}

		lastK = -1

	}

	return count

}