-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay06.kt
More file actions
24 lines (18 loc) · 702 Bytes
/
Copy pathDay06.kt
File metadata and controls
24 lines (18 loc) · 702 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package day06
import common.InputRepo
import common.readSessionCookie
import common.solve
fun main(args: Array<String>) {
val day = 6
val input = InputRepo(args.readSessionCookie()).get(day = day)
solve(day, input, ::solveDay06Part1, ::solveDay06Part2)
}
private fun readCharsUntilAllUnique(list: List<Char>, windowSize: Int): Int {
return list.windowed(windowSize, 1).indexOfFirst { it.toSet().size == it.size } + windowSize
}
fun solveDay06Part1(input: List<String>): Int {
return readCharsUntilAllUnique(input.first().toCharArray().toList(), 4)
}
fun solveDay06Part2(input: List<String>): Int {
return readCharsUntilAllUnique(input.first().toCharArray().toList(), 14)
}