Problem 11
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user