@@ -182,18 +182,19 @@ while (true) {
182182 if (map[i][j] in cars && ! ignore.contains(Pair (i, j))) {
183183 moveCar(i, j)
184184 }
185- // print(map[i][j])
186185 }
187- // println()
188186 }
189- // println()
190187 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- }
188+ findOnlyCar()
189+ }
190+ }
191+
192+ fun findOnlyCar () {
193+ for (i in 0 until row) {
194+ for (j in 0 until col) {
195+ if (map[i][j] in cars) {
196+ println (" $j ,$i " )
197+ exitProcess(0 )
197198 }
198199 }
199200 }
@@ -222,13 +223,10 @@ fun moveCar(row: Int, col: Int) {
222223 }
223224 }
224225 val nextChar = map[nextRow][nextCol]
225- // println("$row, $col, $currentChar $nextRow, $nextCol, $nextChar")
226226
227227 if (nextChar in cars) {
228228 map[row][col] = oldValues[Pair (row, col)]!!
229- // println("set $row, $col, ${map[row][col]}")
230229 map[nextRow][nextCol] = oldValues[Pair (nextRow, nextCol)]!!
231- // println("set $nextRow, $nextCol, ${oldValues[Pair(nextRow, nextCol)]!!}")
232230 return
233231 }
234232
@@ -259,9 +257,7 @@ fun moveCar(row: Int, col: Int) {
259257 newNextChar = currentChar
260258 }
261259 map[row][col] = oldValues[Pair (row, col)]!!
262- // println("set $row, $col, ${map[row][col]}")
263260 map[nextRow][nextCol] = newNextChar
264- // println("set $nextRow, $nextCol, $newNextChar")
265261 ignore.add(Pair (nextRow, nextCol))
266262}
267263
0 commit comments