Retrieving largest indices of the bounded element in a multidimensional array in Scala

StackOverflow https://stackoverflow.com/questions/8421840

سؤال

I have an multidimensional Array:

val M = Array.ofDim[Int](V, N)

Goal is to find largest V dimension index for which there exists a bounded element 0 < w0 <= W and return both indices and element value.

Currently I have this code snippet which works, but wondering if there is a nicer, more efficient way to do this.

M.zipWithIndex.reverse.collectFirst({
  case (arr, ind) if arr.exists(a => a <= W && a > 0) => {
    arr.zipWithIndex.find(a => a._1 <= W && a._1 > 0) match {
      case Some((weight, ind2)) => (ind, ind2, weight)
    }
  }
})

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top