
AoC 2025, Day 3 - Lobby
Wednesday, December 3, 2025 at 12:00 PM
Day 3: Lobby is upon us. Let's get started. Again, spoilers are below for this puzzle. Don't read it if you want to solve this yourself.
After figuring out the gift shop issue, you reach the main elevators, which are offline. A nearby elf says the elevators are fried, but you can try using the escalators to get to the printing department. The escalators are also offline, but thankfully they're not fried and only need electricity, which is conveniently supplied by the emergency batteries nearby.
Your batteries are arranged into a series of banks:
987654321111111
811111111111119
234234234234278
818181911112111
Each line is a bank of batteries, and each digit represents a battery and its joltage rating. The joltage rating for the whole bank is determined by the number formed by the digits on the batteries that you've turned on. As an example, if you have a bank like 12345 and you turn on 2 and 4, your joltage rating is 24.
Your task is to find the sum of maximum joltage ratings for each bank in your puzzle input.
Part 1 is to find the maximum joltage sum when you turn on exactly two batteries in each bank.
Part 2 is like Part 1, except now it's when you turn on exactly twelve batteries in each bank.
Our puzzle input is, once again, converted to a JSON array:
data3 = [
"987654321111111",
"811111111111119",
"234234234234278",
"818181911112111",
];
The rest of the puzzle is specific to each part.
We create a dedicated function called FindJoltage, and for this puzzle, it just takes two for loops to find the largest combination for a single battery bank line:
var FindJoltage = (b) => {
let tmpArr = b.split(""),
joltage = 0;
for (let a = 0; a < tmpArr.length; a++) {
for (let b = a + 1; b < tmpArr.length; b++) {
let newJolt = parseInt(`${tmpArr[a]}${tmpArr[b]}`);
joltage = Math.max(newJolt, joltage);
}
}
return joltage;
};
We then run our data through a reduce transformation, which will automatically summarize the results as it iterates over our array:
var Day3A = (d) => d.reduce((acc, cur) => acc + FindJoltage(cur), 0);
Boom, part done.
There is no way in hell that I'll have 12 for loops in a row to solve this. Let's take a different route.
Change FindJoltage to include a second parameter, i, which stands for how many batteries are turned on per bank:
var FindJoltage = (b, i) => {
let finalArr = [],
startIndex = 0;
The startIndex integer will play a crucial role in our search through the battery banks.
What we want to do is search for the largest digit, starting at a specific point in the bank string and only including valid digits (having to turn on 12 batteries means that your very first battery bank excludes the last 11 digits when searching for a valid match):
for (let j = 1; j <= i; j++) {
for (let k = 9; k >= 0; k--) {
let pattern = new RegExp(k, "g"),
matches = b
.substring(startIndex, b.length - (i - j))
.matchAll(pattern)
.toArray();
If there are any matches, add the first (or leftmost) match to finalArr, and push our startIndex further down the line:
if (matches.length > 0) {
finalArr.push(matches[0]);
startIndex += matches[0].index + 1;
break;
}
Return our final number after joining the array:
return parseInt(finalArr.join(""));
Now we can solve Part 1 and Part 2 by supplying their batteries turned on value:
var Day3A = (d) => d.reduce((acc, cur) => acc + FindJoltage(cur, 2), 0);
var Day3B = (d) => d.reduce((acc, cur) => acc + FindJoltage(cur, 12), 0);
console.log(Day3A(data3));
console.log(Day3B(data3));
Boom, puzzle done.
This was another good one. Not much more to say about it.
My final code:
var data3 = require("./day03.json");
var FindJoltage = (b, i) => {
let finalArr = [],
startIndex = 0;
for (let j = 1; j <= i; j++) {
for (let k = 9; k >= 0; k--) {
let pattern = new RegExp(k, "g"),
matches = b
.substring(startIndex, b.length - (i - j))
.matchAll(pattern)
.toArray();
if (matches.length > 0) {
finalArr.push(matches[0]);
startIndex += matches[0].index + 1;
break;
}
}
}
return parseInt(finalArr.join(""));
};
var Day3A = (d) => d.reduce((acc, cur) => acc + FindJoltage(cur, 2), 0);
var Day3B = (d) => d.reduce((acc, cur) => acc + FindJoltage(cur, 12), 0);
console.log(Day3A(data3));
console.log(Day3B(data3));