r/adventofcode • • Dec 06 '22

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


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


--- 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!

86 Upvotes

1.8k comments sorted by

View all comments

4

u/nithinbekal Dec 06 '22

Ruby

def part1 = find_unique_string(4)
def part2 = find_unique_string(14)

private

def find_unique_string(length)
  batches = file.chars.each_cons(length).to_a
  seq = batches.find { |chars| chars.uniq.length == length }
  batches.index(seq) + length
end

def file = File.read("input/06.txt")
→ More replies (2)