This was a nice and fast one. I always enjoy playing with Regexp. Only Part 2 gave me a struggle, because of my thought process. I tend to do things much more complicated than they should be. :D
Here is a little example:
export function getDoMulCalls(input: string): any {
const startRe = /^(.*?)don\'t\(\)/g;
const middleRe = /do\(\)(.*?)don\'t\(\)/g;
const endRe = /do\(\)(.*?)$/g;
const startDos = Array.from(input.matchAll(startRe), match => match[1]);
const middleDos = Array.from(input.matchAll(middleRe), match => match[1]);
const endDos = Array.from(input.matchAll(endRe), match => match[1]).filter(endDo => !endDo.includes("don't()"));
return [...startDos, ...middleDos, ...endDos].map(getMulCalls).flat();
}
This will not give you the solution to Part 2. I thought this was simple and clever at the same time. But I needed to start fresh and remove the cleverness from the code. Bonus, I've learned something new with JavaScript and Regexp. :)
Part 2 gave me a real struggle. I just got it by luck and think that my original solution is still right, provided all the information there was on the page. Out of desperation, I have thrown my solution for Part 2 overboard and decided to try a different approach. It makes sense. But if you compare it with the information on that page, it makes less to no sense. Until this point, I've had a lot of fun and hopefully the challenge tomorrow is not easier, but the information on the page tells everything you need to know.
In 2023, I've participated in the Advent of Typescript for 8 Days. Currently, I don't understand why I didn't continue with it because it made a lot of fun. This year, I've resolved to complete as much as I can in Advent of Typescript, but also to join the Advent of Code 2024 and do here also as much as I can.
For the Advent of Code 2024, I've decided to make it plain and simple with vite + typescript. To do more Test Driven Development, I will first write a test and add the code after.
Visually, Advent of Typescript looks really nice. They let you write and test your types inside the browser, which makes writing there quite satisfying.
I'll have set up a git repository, which I update after each Day is done. After the Advent of … is done, I'll publish the repo on GitHub.
Day 1 for both was basic. Let's see how the other days will be. I'm looking forward to that, they will be challenging, and I will learn a ton of new stuff.