Last active
December 6, 2022 14:12
-
-
Save bsautner/0bf25eaffdf56cf241106a34f2a46294 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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