-
-
Save waynejo/9ab4f0b2a274eeef46417c207ab11f82 to your computer and use it in GitHub Desktop.
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
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