generated from kotlin-hands-on/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay25.kt
31 lines (28 loc) · 998 Bytes
/
Day25.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fun main() {
fun part1(input: List<String>): Int {
val arr = input.map { it.toMutableList() }
val (x, y) = arr.size to arr[0].size
var count = 0
fun move(ch: Char, dx: Int, dy: Int): Boolean {
val moves = mutableListOf<Pair<Int, Int>>()
for (i in arr.indices) for (j in arr[0].indices)
if (arr[i][j] == ch && arr[(i + dx) % x][(j + dy) % y] == '.')
moves.add(i to j)
for ((i, j) in moves) {
arr[i][j] = '.'
arr[(i + dx) % x][(j + dy) % y] = ch
}
return moves.isNotEmpty()
}
while (true) {
count++
val movedEast = move('>', 0, 1)
val movedSouth = move('v', 1, 0)
if (!movedEast && !movedSouth) return count
}
}
val testInput = readInput("Day25_test")
checkEquals(part1(testInput), 58)
val input = readInput("Day25")
println(part1(input))
}