Minor kotlinization :)

This commit is contained in:
Chris Hodges 2024-12-11 07:54:26 +01:00
parent 34c0c213c4
commit 778b38b3a4

View File

@ -24,26 +24,22 @@ fun main() {
return -1
}
fun rec(n: Long, i: Int): Long {
//println("$i $n")
if (i == 0) return 1
val ll = lookupTable[n to i]
if (ll != null) return ll
val result = if (n == 0L) {
rec(1L, i - 1)
} else {
val size = fastCeilLog10(n)
if (size and 1 == 0) {
val left = n / powTenTable[size / 2]
val right = n % powTenTable[size / 2]
rec(left, i - 1) + rec(right, i - 1)
fun rec(n: Long, i: Int): Long =
if (i == 0) 1 else lookupTable.getOrPut(n to i) {
if (n == 0L) {
rec(1L, i - 1)
} else {
rec(n * 2024L, i - 1)
val size = fastCeilLog10(n)
if (size and 1 == 0) {
val left = n / powTenTable[size / 2]
val right = n % powTenTable[size / 2]
rec(left, i - 1) + rec(right, i - 1)
} else {
rec(n * 2024L, i - 1)
}
}
}
lookupTable[n to i] = result
return result
}
fun part1(input: List<String>): Long {
val numbers = input[0].splitLongs()