@@ -2,7 +2,7 @@ import java.io.File
22import kotlin.system.exitProcess
33
44// input processing
5- val inputs = File (" inputs/day131 .txt" ).readLines()
5+ val inputs = File (" inputs/day13 .txt" ).readLines()
66val map = inputs.map { it.map { it }.toMutableList() }.toMutableList()
77val row = map.count()
88val col = map[0 ].count()
@@ -175,25 +175,27 @@ for (i in 0 until row)
175175 }
176176 }
177177val ignore = mutableSetOf<Pair <Int , Int >>()
178- var clashes = 0
179- var x = 0
180- var y = 0
181178while (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
0 commit comments