Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Punto 1 del opcional de programación funciona
- */
- object Punto1 {
- def inversiones(lst:List[Int]):Int = {
- def inversionesAux(lst:List[Int], acc:Int):Int = lst match {
- case Nil => acc
- case x::xs => inversionesAux(xs, acc + xs.filter(_ < x).length)
- }
- inversionesAux(lst, 0)
- }
- def main(args: Array[String]): Unit = {
- println(inversiones(List(2,3,8,6,1)))
- println(inversiones(List(1,2,3,4)))
- println(inversiones(List(3,2,1)))
- }
- }
- /**
- * Punto 2 del examen opcional
- */
- object Punto2{
- def flatten(lst:List[Any]):List[Int] = {
- lst match{
- case Nil => Nil
- case h::t =>
- h match{
- case x:Int => x::flatten(t)
- case x:List[Any] => flatten(x):::flatten(t)
- }
- }
- }
- def main(arr:Array[String]){
- println(flatten(List(2,List(3,4),8,6,1)))
- println(flatten(List(1,2,List(3,List(4,List(5,6))))))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement