DEV Community

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

Posted on

1

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)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay