예제 #1
0
func main() {
	for i := 0; i < len(input); i++ {
		//My recursive permuation was simply not fast enough
		contCombinations := itertools.Combinations(input, i)
		for _, v := range contCombinations {
			if sum(v...) == LIMIT {
				combinationCount++
			}
		}
	}

	fmt.Println("Combination count:", combinationCount)
}
예제 #2
0
func main() {
	for i := 0; i < len(input); i++ {
		//My recursive permuation was simply not fast enough
		contCombinations := itertools.Combinations(input, i)
		for _, v := range contCombinations {
			if sum(v...) == LIMIT {
				combinationsAndContainerCount[len(v)]++
				combinationCount++
			}
		}
	}

	fmt.Println("Combination count:", combinationCount)
	fmt.Println("Smallest Number of Containers which add up to LIMIT:", combinationsAndContainerCount)
}
예제 #3
0
func main() {
	content, err := ioutil.ReadFile("input.txt")
	if err != nil {
		panic(err)
	}
	content = bytes.TrimSpace(content)
	presents := convertToIntSlice(strings.Split(string(content), "\n"))
	presents = arrayutils.ReverseInt(presents)
	//Part 1
	// limit := sum(presents...) / 3

	//Part 2
	limit := sum(presents...) / 4

	for i := 0; i < len(presents); i++ {
		//My recursive permuation was simply not fast enough
		presCombinations := itertools.Combinations(presents, i)
		for _, v := range presCombinations {
			if sum(v...) == limit {
				presentGroups = append(presentGroups, v)
			}

		}
	}

	var smallestPresentCountGroups [][]int
	smallestPresentCount := math.MaxInt64
	for _, v := range presentGroups {
		if len(v) <= smallestPresentCount {
			smallestPresentCount = len(v)
			smallestPresentCountGroups = append(smallestPresentCountGroups, v)
		}
	}

	if len(smallestPresentCountGroups) > 1 {
		smallestQe := math.MaxInt64
		for _, v := range smallestPresentCountGroups {
			vQe := getQuantumEntanglement(v)
			if vQe < smallestQe {
				smallestQe = vQe
			}
		}
		fmt.Println("Smallest qe", smallestQe)
	} else {
		fmt.Println("Smallest qe: ", getQuantumEntanglement(smallestPresentCountGroups[0]))
	}
}