Skip to content

Instantly share code, notes, and snippets.

@ndnenkov
Created December 6, 2022 15:02
Show Gist options
  • Save ndnenkov/0e725838778728e9e0e879110dc246bf to your computer and use it in GitHub Desktop.
Save ndnenkov/0e725838778728e9e0e879110dc246bf to your computer and use it in GitHub Desktop.
Regex only solution for Advent of Code 2022, Day 6
input = 'mjqjpqmgbljsphdztnvjfqwrcgsmlb'
# Part 1
input.match(/(.)(?!\1)(.)(?!\1|\2)(.)(?!\1|\2|\3)./).end 0 # => 7
# Part 2
input.match(
%r{
(.)(?!.{,12}\1)
(.)(?!.{,11}\2)
(.)(?!.{,10}\3)
(.)(?!.{,9}\4)
(.)(?!.{,8}\5)
(.)(?!.{,7}\6)
(.)(?!.{,6}\7)
(.)(?!.{,5}\8)
(.)(?!.{,4}\9)
(.)(?!.{,3}\10)
(.)(?!.{,2}\11)
(.)(?!.?\12)
(.)(?!\13)
.
}x
).end 0 # => 19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment