Skip to content

Instantly share code, notes, and snippets.

@JRuumis
Created December 6, 2022 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRuumis/05c87e54c31b7045b79f4d41303fd2c7 to your computer and use it in GitHub Desktop.
Save JRuumis/05c87e54c31b7045b79f4d41303fd2c7 to your computer and use it in GitHub Desktop.
Day6 Janis
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