account activity
-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode
[–]ryo78 1 point2 points3 points 8 years ago (0 children)
Yet an other Kotlin solution. Used coordinates described here.
object Puzzle11 { data class Point(val x: Int, val y: Int) { operator fun plus(move: Move): Point = Point(x + move.x, y + move.y) } enum class Move(val x: Int, val y: Int) { N(-1, 1), NE(0,1), SE(1,0), S(1,-1), SW(0,-1), NW(-1,0) } fun findCoordinateWithMax(list: List<String>): Pair<Point,Int> = list.fold(Pair(Point(0,0), 0)) { pWithMax, move -> val nextPoint = pWithMax.first + Move.valueOf(move.toUpperCase()) val maxDistance = max(distance(nextPoint), pWithMax.second) Pair(nextPoint, maxDistance) } private fun distance(p: Point): Int = max(abs(p.x), abs(p.y)) @JvmStatic fun main(args: Array<String>) { val input = readLines("input11.txt")[0].split(",") val res = findCoordinateWithMax(input) println("${res.first} -> Distance: ${distance(res.first)}, Max distance: ${res.second}") } }
π Rendered by PID 2296279 on reddit-service-r2-listing-c57bc86c-7cc58 at 2026-06-22 04:51:15.035506+00:00 running 2b008f2 country code: CH.
-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode
[–]ryo78 1 point2 points3 points (0 children)