DEV Community

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

Posted on

Advent of code - Day 25

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.

And it's the last day of the event! For this one, Advent of Code was merciful. It only takes a few minutes to complete with a simple loop.

All in all this year challenges were great. A few were really complex and interesting, I really encourage you to try it out! But I'm honestly happy that it's over so I can relax and enjoy some time of. Completing all the challenges the day of the release takes time and commitment, I'm really proud I managed to keep up with the game!

Here is my solution for day #25:

function transform(subjectNumber: number, value: number) {
  return (value * subjectNumber) % 20201227

function getLoopSize(id: number) {
  let current = 7
  let iterations = 1
  while (current !== id) {
    current = transform(7, current)
  return iterations

const card = getLoopSize(10943862)
console.log({ card })
const door = getLoopSize(12721030)
console.log({ door })

let resultFromDoor = 12721030
for (let i = 0; i < card - 1; i++) {
  resultFromDoor = transform(12721030, resultFromDoor)


let resultFromCard = 10943862
for (let i = 0; i < door - 1; i++) {
  resultFromCard = transform(10943862, resultFromCard)

Enter fullscreen mode Exit fullscreen mode

Feel free to share your solution in the comments!

Photo by Markus Spiske on Unsplash

Discussion (0)