Skip to content

Instantly share code, notes, and snippets.

@bsautner
Last active December 6, 2022 14:12
Show Gist options
  • Save bsautner/0bf25eaffdf56cf241106a34f2a46294 to your computer and use it in GitHub Desktop.
Save bsautner/0bf25eaffdf56cf241106a34f2a46294 to your computer and use it in GitHub Desktop.
fun main(args: Array<String>) {
val input = File("/home/ben/aoc/input-6.txt").readText()
getFirstMarker(input, 4)
getFirstMarker(input, 14)
}
fun getFirstMarker(data: String, window : Int) {
for (i in 0..data.length) {
if (i + window <= data.length) {
val sample = data.subSequence(i, i + window).toSet()
if (sample.size == window) {
println("answer is ${i + window}")
return
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment