25 lines
770 B
Kotlin
25 lines
770 B
Kotlin
|
import java.io.File
|
||
|
|
||
|
fun main(args: Array<String>) {
|
||
|
val directions = mapOf("n" to (0 to 1),
|
||
|
"s" to (0 to-1),
|
||
|
"ne" to (1 to 1),
|
||
|
"nw" to (-1 to 1),
|
||
|
"se" to (1 to -1),
|
||
|
"sw" to (-1 to -1))
|
||
|
// val instructionString = File("../puzzle_10.txt").readLines().first()
|
||
|
val instructionString = "sw,sw,sw,nw"
|
||
|
var indexX = 0
|
||
|
var indexY = 0
|
||
|
var maxDistance = 0
|
||
|
instructionString.split(",").forEach {
|
||
|
name: String ->
|
||
|
val (dx, dy) = directions[name]!!
|
||
|
indexX += dx
|
||
|
indexY += dy
|
||
|
maxDistance = Math.max(maxDistance, Math.max(Math.abs(indexX), Math.abs(indexY)))
|
||
|
}
|
||
|
println("${Math.max(Math.abs(indexX), Math.abs(indexY))}")
|
||
|
println("$maxDistance")
|
||
|
}
|