Skip to content

Instantly share code, notes, and snippets.

@waynejo
Created February 17, 2023 11:59
Show Gist options
  • Save waynejo/9ab4f0b2a274eeef46417c207ab11f82 to your computer and use it in GitHub Desktop.
Save waynejo/9ab4f0b2a274eeef46417c207ab11f82 to your computer and use it in GitHub Desktop.
import java.io.FileInputStream
import scala.annotation.tailrec
import scala.io.StdIn
def positionOfMarker(input: String, length: Int): Int = {
input.sliding(length).indexWhere(chars => chars.toSet.size == length) + length
}
def solve6_1(input: String): Int =
positionOfMarker(input, 4)
def solve6_2(input: String): Int =
positionOfMarker(input, 14)
@main def solve6(): Unit =
val in = new FileInputStream("example6-2.in")
System.setIn(in)
val input = Iterator.continually(StdIn.readLine()).next()
println(solve6_1(input))
println(solve6_2(input))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment