Solving day 1 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
4:30 Part 2

Have fun!

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

Great Solution using for-loop, just I note for incrementation of the variable increases you would omit if condition and just short it like this: count += current > previous;

xmehdi_
Автор

I always look forward to you doing these.

DavidWoodMusic
Автор

Could you do a quick tutorial on how you set up your Javascript environment or point me to the resource that you used? I want to code along but I've spent all day trying to just configure my IDE and do simple things like importing text from a file (which I assume will be used extensively in future days this month). Thanks! Loving your videos so far!

clairechristenson
Автор

Thank You so much for creating these videos. This is very helpful for beginners. Thanks a lot man

sadeeshkumar
Автор

nice, looking forward to other solutions as problems get harder

zzz-mnyy
Автор

Hey, u have cool videos. R u planning on ending AoC 2019, or recording any other year ?

Also continuing prev post: u can also write shorthand filter/map methods in this case

.filter(Boolean)
.map(Number);

lordkim
Автор

Hey, great video. Do you use any extensions for Visual Studio Code? The command "node day01.js" dosn't work for me.
I tried some node.js extensions, but nothing helped yet.

sarahbuhler
Автор

Thanks for all of your videos. Have been following along to see how you approach these puzzles. Just waiting for your day 21 solution now. For my solution, I went for:

// Part 1
let previousValue = null;
const increases = values.reduce((total, value) => {
const ret = (previousValue && value > previousValue) ? 1 : 0;
previousValue = value;
return total + ret;
}, 0);

// Part 2
let previousTotal;
let increases2 = 0;
for(i = 0; i < (values.length - values.length%3); i++) {
const currentTotal = values[i] + values[i+1] + values[i+2];
if (i > 0 && currentTotal > previousTotal) {
increases2++;
}

previousTotal = currentTotal;
}

AlexanderHolsgrove
Автор

Thank you for the video.. What is "fs" ?

ahmedgharbi
Автор

I keep getting 0 as my answer when I run the file, even though I matched the code to be exactly like yours. Weird. Trying to figure that out. Great video though thanks

xShosTaK
Автор

Hope you'll solve all of them like a year ago ;)

HighRollersLounge