Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day24 #20

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Solve puzzle2
lukasbicus committed Oct 11, 2024
commit 6d1e40048cc4595df12399681b4231b6447122bc
9 changes: 6 additions & 3 deletions scripts/aoc2015/day24/puzzle1.ts
Original file line number Diff line number Diff line change
@@ -80,10 +80,10 @@ const input = [
113,
];

function getLowestQE(packages: number[]) {
function getLowestQE(packages: number[], groupCount = 3) {
// split packages to 3 groups, so common heights of packages is equal (several solutions possible)
// mark all combinations with lowest count of packages as group A
const theAGroups = getPackagesGroupsWithSmallestLengths(packages);
const theAGroups = getPackagesGroupsWithSmallestLengths(packages, groupCount);

console.log("theAGroups", theAGroups);
// compute quantum entanglement (QE) for all combinations
@@ -95,4 +95,7 @@ function getLowestQE(packages: number[]) {
// simpleInput test
// getLowestQE(simpleInput);
// solve for input
getLowestQE(input);
// getLowestQE(input);

// solve puzzle2 for input
getLowestQE(input, 4);
3 changes: 2 additions & 1 deletion scripts/aoc2015/day24/utils.ts
Original file line number Diff line number Diff line change
@@ -28,9 +28,10 @@ export function isThereACombinationOfPackagesWithGivenWeight(

export function getPackagesGroupsWithSmallestLengths(
packages: number[],
groupCount = 3,
): number[][] {
// return [];
const groupWeight = getWeightOfGroup(packages) / 3;
const groupWeight = getWeightOfGroup(packages) / groupCount;
if (groupWeight !== Math.round(groupWeight)) {
throw new Error("Unable to form groups");
}