You are viewing a single comment's thread. Return to all comments →
I am using Scala. This is the solution I found. It uses local mutation but it works. If you know how to make it more functional, please share:
def getTable(n: Int = 1001, k: Int = 1001): Array[Array[Long]] = { val mutableTable: mutable.ArrayBuffer[Array[Long]] = collection.mutable.ArrayBuffer() mutableTable += 1L +: Array.fill(n-1)(0L) for (i <- 1 until k) { val a1 = mutableTable(i-1) :+ 0L val a2 = 0L +: mutableTable(i-1) mutableTable += (0 until n).map( e => (a1(e) + a2(e)) % modulo).toArray } mutableTable.toArray } [...] val table = getTable() [...] println(table(N)(K))
Seems like cookies are disabled on this browser, please enable them to open this website
Different Ways
You are viewing a single comment's thread. Return to all comments →
I am using Scala. This is the solution I found. It uses local mutation but it works. If you know how to make it more functional, please share: