Created
December 6, 2022 13:21
-
-
Save JRuumis/05c87e54c31b7045b79f4d41303fd2c7 to your computer and use it in GitHub Desktop.
Day6 Janis
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 Day6TuningTrouble extends App { | |
val tuningInput: List[Char] = scala.io.Source.fromFile("./Sources/Day6TuningTrouble.txt").toList | |
def tuner(stream: List[Char], currentPosition: Int, sampleSize: Int): String = stream match { | |
case a if a.size >= sampleSize && a.take(sampleSize).toSet.size == sampleSize => s"First position with sample size ${sampleSize} detected at ${currentPosition}" | |
case a :: rest => tuner(rest, currentPosition+1, sampleSize) | |
case _ => s"Error! Packet with sample size ${sampleSize} not detected!" | |
} | |
println(tuner(tuningInput, 4, 4)) | |
println(tuner(tuningInput, 14, 14)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment