[JavaScript] Relatively easy one today
Part 1
function part1(input) {
const split = input.split("\n");
const times = split[0].match(/\d+/g).map((x) => parseInt(x));
const distances = split[1].match(/\d+/g).map((x) => parseInt(x));
let sum = 0;
for (let i = 0; i < times.length; i++) {
const time = times[i];
const recordDistance = distances[i];
let count = 0;
for (let j = 0; j < time; j++) {
const timePressed = j;
const remainingTime = time - j;
const travelledDistance = timePressed * remainingTime;
if (travelledDistance > recordDistance) {
count++;
}
}
if (sum == 0) {
sum = count;
} else {
sum = sum * count;
}
}
return sum;
}
Part 2
function part2(input) {
const split = input.split("\n");
const time = parseInt(split[0].split(":")[1].replace(/\s/g, ""));
const recordDistance = parseInt(split[1].split(":")[1].replace(/\s/g, ""));
let count = 0;
for (let j = 0; j < time; j++) {
const timePressed = j;
const remainingTime = time - j;
const travelledDistance = timePressed * remainingTime;
if (travelledDistance > recordDistance) {
count++;
}
}
return count;
}
Was a bit late with posting the solution thread and solving this since I ended up napping until 2am, if anyone notices theres no solution thread and its after the leaderboard has been filled (can check from the stats page if 100 people are done) feel free to start one up (I just copy paste the text in each of them)
Uses typescript but can be used for both js and ts, I make bots in Javascript using it