Problem 11

This commit is contained in:
2026-03-19 15:39:24 +01:00
parent 787e55eb85
commit 451a728117
2 changed files with 34 additions and 0 deletions
@@ -0,0 +1,17 @@
package ninetyNineScalaProblems
import scala.annotation.tailrec
object Problem11:
def modifiedRunLengthEncode(list: List[Any]): List[Tuple2[Int, Any] | Any] =
@tailrec
def loop(cursor: List[Tuple2[Int, Any]], acc: List[Tuple2[Int, Any] | Any]): List[Tuple2[Int, Any] | Any] =
cursor match
case d :: tail if d._1 > 1 =>
loop(tail, (d._1, d._2) :: acc)
case d :: tail =>
loop(tail, d._2 :: acc)
case Nil =>
acc
loop(Problem10.runLengthEncode(list), List()).reverse