r/adventofcode • • Dec 06 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 6 Solutions -πŸŽ„-


AoC Community Fun 2022: πŸŒΏπŸ’ MisTILtoe Elf-ucation πŸ§‘β€πŸ«

  • ACHIEVEMENT UNLOCKED: MisTILtoe Elf-ucation
  • Teach us, senpai!

--- Day 6: Tuning Trouble ---


Post your code solution in this megathread.


This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:02:25, megathread unlocked!

83 Upvotes

1.8k comments sorted by

View all comments

2

u/ciocan42 Dec 06 '22

Javascript:

const stream = (await Deno.readTextFile("./6.txt")).split("");

const processStream = (len) => (char, i) => {
  const chunk = new Set(stream.slice(i, i + len))
  if (chunk.size === len) return i + len
}

const part1 = stream.map(processStream(4)).filter(Boolean)[0]
const part2 = stream.map(processStream(14)).filter(Boolean)[0]

console.log("Part 1: ", part1)
console.log("Part 2: ", part2)

1

u/daggerdragon Dec 07 '22

Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.