joelpedraza
12/07/2018, 7:05 PMjoelpedraza
12/08/2018, 12:01 AMketurn
12/08/2018, 4:45 AMandyb
12/08/2018, 7:08 AMJoris PZ
12/08/2018, 7:24 AM61/2
, JS 62/4
, native 47/38
todd.ginsberg
12/08/2018, 3:11 PMclass Day08(rawInput: String) {
private val tree: Node = Node.of(rawInput.split(" ").map { it.toInt() }.iterator())
fun solvePart1(): Int =
tree.metadataTotal
fun solvePart2(): Int =
tree.value
private class Node(children: List<Node>, metadata: List<Int>) {
companion object {
fun of(values: Iterator<Int>): Node {
val numChildren: Int = values.next()
val numMetadata: Int = values.next()
val children = (0 until numChildren).map { Node.of(values) }
val metadata = (0 until numMetadata).map { values.next() }.toList()
return Node(children, metadata)
}
}
val metadataTotal: Int =
metadata.sum() + children.sumBy { it.metadataTotal }
val value: Int =
if (children.isEmpty()) metadata.sum()
else metadata.map { children.getSafely(it)?.value ?: 0 }.sum()
private fun List<Node>.getSafely(i: Int): Node? =
if (i > this.size) null
else this[i - 1]
}
}
karelpeeters
12/08/2018, 3:17 PMtailrec
is only if you recurse only once per call at most, right?karelpeeters
12/08/2018, 7:51 PMList(...) { ... }
, which reads a bit funny simple smilekarelpeeters
12/08/2018, 8:05 PMcallatz_tailrec
once, while in the challenge you need to call it n
times.keturn
12/08/2018, 9:03 PMkarelpeeters
12/08/2018, 9:15 PMlittlelightcz
12/09/2018, 9:43 AMJoris PZ
12/09/2018, 9:56 AMRostyslav
12/09/2018, 11:55 AMJoris PZ
12/09/2018, 12:37 PM911/563 ms
, JS 7972/5725 ms
. Native did not finish but exited very quickly with
Process finished with exit code -1,073,741,571.
Anyone have any idea how I can find out what went wrong there? My native debugging skills are less than weakfdlk
12/09/2018, 3:21 PMLinkedList
with listIterator()
to work. Quite simple to make it circular. Took some debugging to get the off-by-one cases right. https://github.com/fdlk/advent-2018/blob/5093cbd1006f017b9400a25a27c58a2feec6358a/src/main/kotlin/nl/kelpin/fleur/advent2018/Day09.ktjoelpedraza
12/09/2018, 3:24 PMtodd.ginsberg
12/09/2018, 5:26 PMtodd.ginsberg
12/09/2018, 5:34 PMtodd.ginsberg
12/09/2018, 10:27 PMfelipecsl
12/09/2018, 10:43 PMkef
12/10/2018, 12:53 AMJoris PZ
12/10/2018, 8:22 AM262/44
, JS 454/254
, native 5830/5830
(first run was the best)littlelightcz
12/10/2018, 10:00 AMlittlelightcz
12/10/2018, 11:41 AMtodd.ginsberg
12/10/2018, 3:31 PMkarelpeeters
12/10/2018, 5:40 PMandyb
12/10/2018, 6:02 PMtodd.ginsberg
12/10/2018, 8:43 PMjoelpedraza
12/11/2018, 11:41 AM