Solving day 6 of Advent of Code 2022 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
5:36 Part 2

Have fun!

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

Glad you were as surprised as me :D it's quite nice to have an easy day between all the parsing and sorting!

HerrSiering
Автор

See you tomorrow! Thanks for the quick one today.

queuebit
Автор

Nice videos. I'm doing these puzzles in Javascript too, even though I don't code much in JS. It's interesting to see how someone else approaches the problems. I'm not sure if I have it me to complete all 25 days, but will do my best, and I'll be following your progress. :)

jimraynor
Автор

You're really motivating me :) thanks for that!

fluffig
Автор

Your videos are great! I just subscribed. I am trying to improve my JS algorithm skills! For this one, I think I found a nice solution. I cast a slice of the array to a set and if the set is the same length of the slice array, I know all the values are unique. Works for both part 1 + 2 (part 2 solution below):

function findMessage(input_array) {

let message_start;

for (let i = 0; i < input_array.length; i++) {

const unique_signal = new Set([...input_array.slice(i, i+14)]);

if (unique_signal.size === 14) { // 4 distinct characters
message_start = i + 14;
break;
}
}
return message_start;
}

harleyharris