Skip to content

Commit 00aaf69

Browse files
author
AshleySi
committed
part 2
1 parent c95709e commit 00aaf69

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

Day13.kts

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import java.io.File
22
import kotlin.system.exitProcess
33

44
// input processing
5-
val inputs = File("inputs/day131.txt").readLines()
5+
val inputs = File("inputs/day13.txt").readLines()
66
val map = inputs.map { it.map { it }.toMutableList() }.toMutableList()
77
val row = map.count()
88
val col = map[0].count()
@@ -175,25 +175,27 @@ for (i in 0 until row)
175175
}
176176
}
177177
val ignore = mutableSetOf<Pair<Int, Int>>()
178-
var clashes = 0
179-
var x = 0
180-
var y = 0
181178
while (true) {
182179
ignore.clear()
183-
clashes = 0
184180
for (i in 0 until row) {
185181
for (j in 0 until col) {
186182
if (map[i][j] in cars && !ignore.contains(Pair(i, j))) {
187183
moveCar(i, j)
188184
}
189185
// print(map[i][j])
190186
}
191-
println()
187+
//println()
192188
}
193-
println()
194-
if (clashes == 0) {
195-
println("$y,$x")
196-
exitProcess(0)
189+
//println()
190+
if (map.fold(0) { acc, c -> acc + c.filter { it in cars }.count() } == 1) {
191+
for (i in 0 until row) {
192+
for (j in 0 until col) {
193+
if (map[i][j] in cars) {
194+
println("$j,$i")
195+
exitProcess(0)
196+
}
197+
}
198+
}
197199
}
198200
}
199201

@@ -220,14 +222,13 @@ fun moveCar(row: Int, col: Int) {
220222
}
221223
}
222224
val nextChar = map[nextRow][nextCol]
223-
println("$row, $col, $currentChar $nextRow, $nextCol, $nextChar")
225+
//println("$row, $col, $currentChar $nextRow, $nextCol, $nextChar")
224226

225227
if (nextChar in cars) {
226-
clashes++
227228
map[row][col] = oldValues[Pair(row, col)]!!
228-
println("set $row, $col, ${map[row][col]}")
229+
//println("set $row, $col, ${map[row][col]}")
229230
map[nextRow][nextCol] = oldValues[Pair(nextRow, nextCol)]!!
230-
println("set $nextRow, $nextCol, ${oldValues[Pair(nextRow, nextCol)]!!}")
231+
//println("set $nextRow, $nextCol, ${oldValues[Pair(nextRow, nextCol)]!!}")
231232
return
232233
}
233234

@@ -258,9 +259,9 @@ fun moveCar(row: Int, col: Int) {
258259
newNextChar = currentChar
259260
}
260261
map[row][col] = oldValues[Pair(row, col)]!!
261-
println("set $row, $col, ${map[row][col]}")
262+
//println("set $row, $col, ${map[row][col]}")
262263
map[nextRow][nextCol] = newNextChar
263-
println("set $nextRow, $nextCol, $newNextChar")
264+
//println("set $nextRow, $nextCol, $newNextChar")
264265
ignore.add(Pair(nextRow, nextCol))
265266
}
266267

inputs/day131.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)