Solving day 9 of Advent of Code 2021 in JavaScript

preview_player
Показать описание
Advent of Code is a website that releases a new programming puzzle every day between the 1st and the 25th of December.

0:00 Part 1
16:00 Part 2

Have fun!

Рекомендации по теме
Комментарии
Автор

For these puzzels I really like the console.table(array) to display my inputs.

mpl
Автор

I love watching you code this stuff right off the bat, you're crazy good. I wish you had a sub video series where you go through each day and breakdown/explain every step of the puzzles :) I know it would help me a lot! I got to the if statement on part 1 and you broke my brain haha. But you definitely give me something to google search and look at for hours on end haha. Thank you for these.

xShosTaK
Автор

I think instead of looping through all places to floodfill you can just start in your low points from part 1. Anyway as always great walk through! :) Been following you since last year and you have a similar way of solving the problems and I also do it in js so nice to see how you do it and also learn some new stuff!

annsofipettersson
Автор

Thanks for sharing your walkthrough.

I'll have to check it out again to see what situation I am not handling with part 2.

queuebit
Автор

Amazing video once more, I like to see the way you go through each problem, and it sometimes reflects the way I solved it or else I get to learn a new technique, or a term in this case (floodfill) I used floodfill in my solution without realizing it.

I do it in python and have tried to learn Js but quit because I didn't find it interesting nut after watching your videos I wanna learn JS again, thank u for the motivation. I also watch another Youtuber who di AoC in Java. Its nice to see and underastand how other languages work as well

ans
Автор

For part 1 I did a get function, where you do not have to care for the matrix boundaries. Is the value undefined it is outside and thus greater than the value.

const get = (a, x, y) => (a[y] || [])[x];
const isGreat = (less) => (than) => {
if (than === undefined) return true;
return less < than;
};
const solve1 = (a) => {
let res = 0;
for (let y = 0; y < a.length; y += 1) {
for (let x = 0; x < a[y].length; x += 1) {
const num = get(a, x, y);
if ([
get(a, x - 1, y),
get(a, x, y - 1),
get(a, x + 1, y),
get(a, x, y + 1),
].every(isGreat(num))
) {
res += num + 1;
}
}
}
return res;
};

rowolta
Автор

Good job, keep going , can zoom in vscode please 🙏

asf