Minor kotlinization :)

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

View File

@ -24,12 +24,9 @@ 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) {
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 {
val size = fastCeilLog10(n)
@ -41,10 +38,9 @@ fun main() {
rec(n * 2024L, i - 1)
}
}
lookupTable[n to i] = result
return result
}
fun part1(input: List<String>): Long {
val numbers = input[0].splitLongs()
return numbers.sumOf { rec(it, 25) }