Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Practica 5
- -- head
- hd :: [Int] -> Int
- hd (x:xs) = x
- -- tail
- tl :: [Int] -> [Int]
- tl (x:xs) = xs
- -- last
- -- FALTARIA VER QUE HACES EN EL CASO DE QUE HACES EL lt DE UNA LISTA VACIA
- lt :: [Int] -> Int
- -- lt [] = error "lista vacia"
- lt (x:xs) | (xs == []) = x
- | otherwise = lt xs
- -- init
- -- FALTARIA VER QUE HACES EN EL CASO DE QUE HACES EL innit DE UNA LISTA VACIA
- innit :: [Int] -> [Int]
- -- innit [] = error "lista vacia"
- innit (x:xs) | (xs == []) = []
- | otherwise = [x] ++ innit xs
- -- Cuenta cuantos elementos hay en una lista
- -- FALTA EL PERFIL DE LA FUNCION
- -- FALTARIA VER QUE HACES EN EL CASO DE QUE HACES EL contatoria DE UNA LISTA VACIA
- -- contatoria [] = 0
- contatoria (x:xs) | (xs == []) = 1
- | otherwise = 1 + contatoria xs
- -- Devuelve True si el numero es primo.. False si no lo es
- esPrimo :: Int -> Bool
- esPrimo x | contatoria(divList x) == 2 = True
- | otherwise = False
- where divList x = [n | n <- [1..x], (mod x n == 0)]
- -- Tira una lista de numeros primos entre la lista de numeros pasadas
- -- FALTARIA VER QUE HACES EN EL CASO DE QUE HACES EL esPrimoLista DE UNA LISTA VACIA
- -- esPrimoLista [] = []
- esPrimoLista :: [Int] -> [Int]
- esPrimoLista (x:xs) | (xs == []) && (esPrimo x) = [x]
- | (xs == []) && (esPrimo x == False) = []
- | x == 1 = [x]++ esPrimoLista xs
- | esPrimo x = [x]++ esPrimoLista xs
- | otherwise = [] ++ esPrimoLista xs
- -- Devuelve los numeros primos hasta el Numero dado
- esPrimoListNum :: Int -> [Int]
- esPrimoListNum x = esPrimoLista [1..(x-1)]
- -- Revierte una lista upsideDown
- reversa :: [Int] -> [Int]
- reversa [] = []
- reversa (x:xs) = reversa xs ++ [x]
- -- Devuelve True si las listas son Identicas
- compararListas :: [Int] -> [Int] -> Bool
- compararListas [] [] = True
- compararListas _ [] = False
- compararListas [] _ = False
- compararListas (x:xs) (y:ys) | (x == y) = compararListas xs ys
- | otherwise = False
- -- Devuelve True si el numero es capicua
- palindromo :: [Int] -> Bool
- palindromo [] = True
- palindromo [x] = True
- palindromo (x:xs) | (x == lt xs) = palindromo (innit xs)
- | otherwise = False
- -- Une 2 listas previamente ordenadas de modo ordenado
- mergeLista :: [Int] -> [Int] ->[Int]
- mergeLista [] [] = []
- mergeLista x [] = x
- mergeLista [] y = y
- mergeLista (x:xs) (y:ys) | x <= y = [x] ++ mergeLista xs (y:ys)
- | otherwise = [y] ++ mergeLista (x:xs) ys
- -- Ordena una lista
- quickSort :: [Int] -> [Int]
- quickSort [] = []
- quickSort (x:xs) = smallSort ++ [x] ++ bigSort
- where
- smallSort = quickSort [a | a <- (xs), a<= x];
- bigSort = quickSort [b | b <- (xs), b > x]
- -- 2^n solo usando multiplicacion
- potDos :: Int -> Int
- potDos 0 = 1
- potDos x = 2 * potDos (x-1)
- -- Devuelve un num binario de un decimal (Invertido)
- decABinarioInver :: Int -> [Int]
- decABinarioInver 0 = [0]
- decABinarioInver x | x < 2 = [1]
- | otherwise = [(mod x 2)] ++ decABinarioInver (div x 2)
- --OTRA FORMA DE SOLUCIONAR EL INVERTIDO ES decABinarioInver (div x 2) ++ [(mod x 2)]
- -- Arregla la funcion anterior
- decABinario :: Int -> [Int]
- decABinario x = reversa (decABinarioInver x)
- -- Cuadrado Perfecto
- cuadPerfecto :: Int -> Bool
- cuadPerfecto x | [a | a <- [1..x], (a*a) == x] == [] = False
- | otherwise = True
- -- Quitar una sublista de una lista
- -- FALTARIA OTRO CASO
- quitarDeLista :: [Int] -> [Int] -> [Int]
- -- quitarDeLista [] xs = xs
- quitarDeLista (x:xs) [] = []
- quitarDeLista (x:xs) (y:ys) | x == y = ys
- | otherwise = [y] ++ quitarDeLista (x:xs) ys
- -- FIJATE QUE VOS LE ESTAS SACANDO EL PRIMER ELEMENTO DE LA SUBLISTA A LA LISTA Y POR LO QUE ME DECIS
- -- EN LA DESCRIPCION DE LA FUNCION TENES QUE SACAR TODA LA SUBLISTA DE LA LISTA
- -- EJ: quitarDeLista [1,2] [1,2,3,4] => [3,4] Y VOS RETORNAS [2,3,4]
- -- Devuelve True si una lista es permutacion de otra
- esPerm :: [Int] -> [Int] -> Bool
- esPerm [] [] = True
- esPerm _ [] = False
- esPerm [] _ = False
- esPerm (x:xs) ys | [a | a <- ys, a == x] /= [] = esPerm xs (quitarDeLista [a | a <- ys, a == x] ys)
- | otherwise = False
- -- Suma los elementos de una lista
- sumaLista :: [Float] -> Float
- sumaLista [] = 0
- sumaLista (x:xs) = x + sumaLista xs
- -- Devuelve el promedio de una lista dew Reales
- promReales :: [Float] -> Float
- promReales [] = 0
- promReales (x:xs) = (sumaLista (x:xs))/contatoria (x:xs)
- -- ===========================================
- -- Dada una lista, tenes que devolver una lista con todas las permutaciones posibles
- -- PERFIL DE LA FUNCION:
- -- permuta :: [Int] -> [[Int]]
- -- EJEM: [1,2,3] => [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
Add Comment
Please, Sign In to add comment