From baa5db467feb98e35ab7f555ea5b9e55a5d52312 Mon Sep 17 00:00:00 2001 From: Bas Dado Date: Thu, 12 Dec 2019 01:05:27 +0100 Subject: [PATCH] Day 10 code cleanup --- .../com/basdado/adventofcode/day10/Day10.kt | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/main/kotlin/com/basdado/adventofcode/day10/Day10.kt b/src/main/kotlin/com/basdado/adventofcode/day10/Day10.kt index ab58060..5b82ca2 100644 --- a/src/main/kotlin/com/basdado/adventofcode/day10/Day10.kt +++ b/src/main/kotlin/com/basdado/adventofcode/day10/Day10.kt @@ -10,23 +10,6 @@ import kotlin.math.min const val DAY10_INPUT_PATH = "/day/10/input.txt" fun main() { - -// val circle = listOf( -// Day10.Vector2i(0, 1), -// Day10.Vector2i(1, 1), -// Day10.Vector2i(1, 0), -// Day10.Vector2i(0, -1), -// Day10.Vector2i(-1, -1), -// Day10.Vector2i(-1, 0), -// Day10.Vector2i(-1, 1) -// ) -// -// circle.map { -// - (it.angle() + 0.5 * PI) -// }.map { if (it < 0) it + 2 * PI else it }.forEach(::println) - -// println(Day10.Vector2i(5, 2).angle()) - Day10.puzzle1() Day10.puzzle2() } @@ -42,20 +25,14 @@ object Day10 { fun puzzle2() { val asteroids = loadAsteroids() val optimalAsteroid = optimalAsteroidsPerDirection(asteroids) -// val optimalAsteroid = Pair(Vector2i(8, 3), asteroidsPerDirection(Vector2i(8, 3), asteroids)) // println(optimalAsteroid.first) -// optimalAsteroid.second.keys.forEach { -// var angle = (it.angle() + 0.5 * PI); -// angle = if (angle < 0) 2*PI + angle else angle -// println("(${it.x}, ${it.y}) = $angle") -// } val sortedAsteroidLists = optimalAsteroid.second .entries .sortedBy { val angle = (it.key.angle() + 0.5 * PI); if (angle < 0) 2*PI + angle else angle } .map { it.value.sortedBy( Vector2i::manhattan ) } // And now we're gonna keep taking one of each list until we reach number 200 var listIndex = 0 - var itemIndexPerList = IntArray(sortedAsteroidLists.size) + val itemIndexPerList = IntArray(sortedAsteroidLists.size) var i = 0 var curItem: Vector2i? = null while (i < 200) { @@ -108,8 +85,6 @@ object Day10 { operator fun plus(v: Vector2i) = Vector2i(x + v.x, y + v.y) } - val ORIGIN = Vector2i(0, 0) - fun gcd(n1: Int, n2: Int) = when { n1 == 0 && n2 == 0 -> 1 // Actually undefined/any number, but whatever n1 == 0 -> abs(n2)