Skip to content

Commit

Permalink
day 13, part 2 is still very slow but shows progress
Browse files Browse the repository at this point in the history
  • Loading branch information
dieseltravis committed Dec 14, 2024
1 parent 4099b0a commit fc4255d
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions public/funs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,6 @@
part2: (data) => {
const matchButtons = /X\+(\d+), Y\+(\d+)/;
const matchPrize = /X=(\d+), Y=(\d+)/;
let sum = 0;
const input = data.trim().split('\n\n').map(r => {
const claw = r.split('\n');
const buttonA = claw[0].match(matchButtons);
Expand All @@ -1070,10 +1069,17 @@
y: +prize[2] + 10000000000000
}
};
return game;
});
const ymax = input.length;
console.log(input, ymax);
const sum = input.reduce((acc, game, i) => {
// start at max B value
const bmax = Math.min(game.p.x / game.b.x, game.p.y / game.b.y);
const bmax = Math.floor(Math.min(game.p.x / game.b.x, game.p.y / game.b.y)) + 1;
const percentage = bmax / 100;
let last = bmax;
let percent = 100;
console.log('processing ' + (i + 1) + ' of ' + ymax + ', counting down from ' + bmax);
for (let b = bmax; b--;) {
const bx = b * game.b.x;
if (bx <= game.p.x) {
Expand All @@ -1091,21 +1097,22 @@
game.p.b = b;
game.p.a = axv;
game.p.t = (axv * 3) + b;
sum += game.p.t;
acc += game.p.t;
console.log(acc, game.p.t);
break;
}
}
}
}
}
if (b < percent * percentage) {
if (b < last) {
console.log((100 - percent) + '%');
last -= percentage;
percent--;
}
}
return game;
});
console.log(input, sum);
return acc;
}, 0);
return sum;
}
},
Expand Down

0 comments on commit fc4255d

Please sign in to comment.