DEV Community

Cover image for Advent of code - Day 3
Quentin Ménoret
Quentin Ménoret

Posted on

Advent of code - Day 3

Are you participating in the Advent of code this year?

If you don't know what the advent of code is, it's a website where you'll find a daily challenge (every day it gets harder). It's a really fun event, you should participate!

I try to solve the exercises using either JavaScript or TypeScript and will share my solutions daily (with one day delay so no one can cheat!). I only share the solution for the second part.

Here is my solution for day #3:

[ [1, 1], [3, 1], [5, 1], [7, 1], [1, 2], ] .map( ([RIGHT, DOWN]) => $('body > pre') .textContent.split(/\r?\n/) .filter(Boolean) .filter((_, index) => index % DOWN === 0) .filter((value, index) => value[(index * RIGHT) % value.length] === '#').length, ) .reduce((acc, v) => acc * v, 1) 
Enter fullscreen mode Exit fullscreen mode

Feel free to share yours in the comments!


Photo by Markus Spiske on Unsplash

Top comments (0)