Created
December 6, 2022 15:54
-
-
Save cyberzac/88755bc346ce228f181b170d00342aa6 to your computer and use it in GitHub Desktop.
AdventOfCode 2022
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
object Day6 extends Day : | |
def part1(input: Iterator[String]) = | |
markerFinder(input, 4) | |
private def markerFinder(input: Iterator[String], length: Int): String = { | |
input.map(_ | |
.sliding(length) | |
.map(_.toSet.size) | |
.zipWithIndex | |
.collectFirst { | |
case (`length`, i) => i + length | |
}.get | |
).mkString(" ") | |
} | |
def part2(input: Iterator[String]) = | |
markerFinder(input, 14) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment