From 1730dfe9554830b5971bf4a7669a3920729c3d8c Mon Sep 17 00:00:00 2001 From: Bas Dado Date: Tue, 11 Dec 2018 17:38:14 +0100 Subject: [PATCH] Day 11 cleanup --- .../kotlin/com/basdado/adventofcode/Day11.kt | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/basdado/adventofcode/Day11.kt b/src/main/kotlin/com/basdado/adventofcode/Day11.kt index 409e18e..f2bb372 100644 --- a/src/main/kotlin/com/basdado/adventofcode/Day11.kt +++ b/src/main/kotlin/com/basdado/adventofcode/Day11.kt @@ -1,7 +1,5 @@ package com.basdado.adventofcode -import kotlin.math.roundToInt -import kotlin.math.sqrt import kotlin.system.measureTimeMillis fun main() { @@ -87,13 +85,14 @@ class Day11 { } class PowerCell(val x: Int, val y: Int, val gridSerial: Int) { - val rackId = x + 10 + private val rackId = x + 10 val powerLevel = hundreds(((rackId * y) + gridSerial) * rackId) - 5 } - class PowerBlockCache(val maxSize: Int, val maxX: Int, val maxY: Int) { - val cache = Array(maxSize) { size -> Array(maxX - size) { Array(maxY - size) {null}}} + class PowerBlockCache(maxSize: Int, private val maxX: Int, private val maxY: Int) { + + private val cache = Array(maxSize) { size -> Array(maxX - size) { Array(maxY - size) {null}}} fun get(x: Int, y: Int, size: Int): Int? { return cache[size - 1][x][y] @@ -109,15 +108,5 @@ class Day11 { fun hundreds(x: Int): Int { return (x - ((x / 1000) * 1000)) / 100 } - - @JvmStatic - fun divisor(n: Int): Int? { - return DEFAULT_DIVISORS.find { n % it == 0 && it < n } ?: - (DEFAULT_DIVISORS.last()..sqrt(n.toDouble()).roundToInt()).find { n % it == 0 } - } - - private val DEFAULT_DIVISORS = intArrayOf(2, 3, 5, 7, 11, 13, 17, 19) } - - data class PowerBlock(val x: Int, val y: Int, val size: Int) } \ No newline at end of file