[scala] - brute force
I am deeply concerned by the amount of attention given to Scala. Please submit your solutions and upvote.\n\n\nobject Solution {\n  \n  case class C(i: Int, j: 
I am deeply concerned by the amount of attention given to Scala. Please submit your solutions and upvote.\n\n```\nobject Solution {\n  \n  case class C(i: Int, j: Int)\n\n  def resultGrid(image: Array[Array[Int]], threshold: Int): Array[Array[Int]] = {\n    val avgs =\n      (for {\n        i <- image.indices.tail.init\n        j <- image(0).indices.tail.init\n        avg <- listAvgs(image, threshold, C(i, j))\n      } yield avg).groupMap(_._1)(_._2)\n\n    image.indices.toArray.map { i =>\n      image(i).indices.toArray.map { j =>\n        avgs.get(C(i, j)).fold(image(i)(j))(nel => nel.sum / nel.size)\n      }\n    }\n  }\n\n  private def listAvgs(image: Array[Array[Int]], threshold: Int, center: C): List[(C, Int)] = {\n    val region = neighbor9(center)\n    val inThreshold = region.forall { c1 =>\n      neighbor4(c1).filter(region.contains).forall { c2 =>\n        math.abs(image(c1.i)(c1.j) - image(c2.i)(c2.j)) <= threshold\n      }\n    }\n    val avg = region.map(c => image(c.i)(c.j)).sum / 9\n    if (inThreshold) region.map(_ -> avg) else List.empty\n  }\n\n  private def neighbor9(c: C): List[C] =\n    List(\n      C(c.i - 1, c.j - 1), C(c.i - 1, c.j), C(c.i - 1, c.j + 1),\n      C(c.i, c.j - 1),     C(c.i, c.j),     C(c.i, c.j + 1),\n      C(c.i + 1, c.j - 1), C(c.i + 1, c.j), C(c.i + 1, c.j + 1),\n    )\n\n  private def neighbor4(c: C): List[C] =\n    List(C(c.i - 1, c.j), C(c.i + 1, c.j), C(c.i, c.j - 1), C(c.i, c.j + 1))\n}\n```
['Scala']