Day 6 optimized
This commit is contained in:
parent
3cb7439ebc
commit
f2497d4e3a
1 changed files with 60 additions and 0 deletions
60
day6/part2-optimized.kts
Normal file
60
day6/part2-optimized.kts
Normal file
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env kotlin
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun MutableList<MutableList<Char>>.clone(): MutableList<MutableList<Char>> {
|
||||
val grid = mutableListOf<MutableList<Char>>()
|
||||
var i = 0;
|
||||
this.forEach {
|
||||
grid.add(MutableList(it.size) { j ->
|
||||
this[i][j]
|
||||
})
|
||||
i++
|
||||
}
|
||||
|
||||
return grid
|
||||
}
|
||||
|
||||
enum class Direction {
|
||||
UP,
|
||||
DOWN,
|
||||
RIGHT,
|
||||
LEFT;
|
||||
|
||||
fun rotate90(): Direction {
|
||||
return when (this) {
|
||||
UP -> RIGHT
|
||||
DOWN -> LEFT
|
||||
RIGHT -> DOWN
|
||||
LEFT -> UP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var originalGrid = mutableListOf<MutableList<Char>>()
|
||||
|
||||
var originalGuy = Pair(0, 0);
|
||||
var originalDirection = Direction.UP
|
||||
|
||||
var i = 0
|
||||
File("./input.txt").forEachLine {
|
||||
val iter = it.chars().iterator()
|
||||
var j = 0
|
||||
originalGrid.add(MutableList(it.length) {
|
||||
var next = iter.next().toChar()
|
||||
|
||||
if (next == '^') {
|
||||
originalGuy = Pair(i, j)
|
||||
next = '.'
|
||||
}
|
||||
|
||||
j++
|
||||
next
|
||||
})
|
||||
|
||||
i++
|
||||
}
|
||||
|
||||
|
||||
|
||||
println("\n" + sum)
|
Loading…
Reference in a new issue