Problem 25

This commit is contained in:
2026-03-19 16:02:23 +01:00
parent 744de4fd94
commit 0c522de9cc
2 changed files with 26 additions and 0 deletions
@@ -0,0 +1,16 @@
package ninetyNineScalaProblems
import scala.util.Random
import scala.annotation.tailrec
object Problem25:
def randomPermute(list: List[Any]): List[Any] =
@tailrec
def loop(cursor: List[Any], acc: List[Any]): List[Any] =
cursor match
case head :: tail =>
loop(tail, cursor(Random.between(0, cursor.length)) :: acc)
case Nil =>
acc
loop(list, List())