LOADING: An error occurred. Update Chrome, try Firefox, or visit this post for more details.

⚠️Reddit changed how removals work, which breaks Reveddit's website. Install the extension to track removed content:Add to chromeAdd to firefoxWhat changed?
✖︎
about reveddit
⚙F.A.Q.add-ons
r/
status
copy sharelink
[+] show filters
83
SOLUTION MEGATHREAD-🎄- 2022 Day 6 Solutions -🎄-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 4 hours, 17 minutes after) by daggerdragon to /r/adventofcode (134.8k)
1762 commentsredditother-discussionssubreddit-indexmessage modsop-focus
  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • A reque...

... view full text

since 3 years, 1 month ago
3 of 3

Tip Reveddit Real-Time can notify you when your content is removed.

your account history
(check your username's removed content. why?)
Tip Check if your account has any removed comments.
view my removed comments
you are viewing a single comment's thread.
view all comments
[–]nithinbekal5 points3 years, 1 month ago

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")
permalinkhide replies (1)author-focusas-ofpreserve
[–][deleted]1 point3 years, 1 month ago

Nice!

If you care about performance, you might consider using find_index instead of calling looping twice in both find and index. If you choose to do that, you might also want to leave batches as an enumerable, rather than converting it to an array.

permalinkparentcontexthide replies (1)as-of
[–]nithinbekal2 points3 years, 1 month ago

Ooh, I really like that! I seem to be learning about new Enumerable methods every day during AOC. Thanks for sharing that. :)

Refactored solution: https://github.com/nithinbekal/advent-of-code/blob/c3788728010d8bcacd1d622996ef56226ba0370a/lib/06.rb

permalinkparentcontextauthor-focusas-ofpreserve
r/revedditremoved.substack.com
🚨 NEWS 🚨
✖︎

Important: Reddit Changed How Removals Work

A recent Reddit update makes mod-removed content disappear from profile pages, which breaks Reveddit's website.

Install the browser extension to receive removal alerts.

Add to chromeAdd to firefox

What changed?

r/revedditremoved.substack.com