Skip to content

Instantly share code, notes, and snippets.

@Yuichiroh
Created April 2, 2015 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuichiroh/810d292276d6d87bd79b to your computer and use it in GitHub Desktop.
Save Yuichiroh/810d292276d6d87bd79b to your computer and use it in GitHub Desktop.
val scores = Array(
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5),
Array(1, 2, 3, 4, 5)
)
val bests = Array.fill(5)(Array.fill(5)(0))
scores(0).copyToArray(bests(0))
for {
i <- 1 until 5
best = bests(i - 1).max
j <- 0 until 5
} {
bests(i)(j) = best + scores(i)(j)
}
println(bests(4).toSeq) // WrappedArray(1, 2, 3, 4, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment