Created
December 6, 2022 15:02
-
-
Save ndnenkov/0e725838778728e9e0e879110dc246bf to your computer and use it in GitHub Desktop.
Regex only solution for Advent of Code 2022, Day 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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