module Clase10Set where import Naturales -- practico 7 iguales :: N->N->Bool iguales Z Z=True iguales Z a=False iguales a Z=False iguales (S a) (S b) = iguales a b menor :: N->N->Bool menor Z Z=False menor Z a=True menor a Z=False menor (S a) (S b) = menor a b suma :: N->N->N suma Z Z=Z suma Z a=a suma (S a) b= S(suma a b) --OR oro :: Bool->Bool->Bool oro False False = False oro _ _ = True producto :: N->N->N producto Z Z=Z producto Z a=Z producto a Z=Z producto (S a) b= suma (producto a b) (b) potencia :: N->N->N potencia Z Z= error "no está definido" potencia Z a=Z potencia a Z=S Z potencia a (S b) =producto (potencia a b) (a) --Suma hasta n suman :: N->N suman Z =Z suman (S a)= suma (suman a) (S a) --Practico 8 saca3::[Integer]->[Integer] saca3 [] = [] saca3 (a:xs) = if a==3 then saca3(xs) else a:saca3(xs) --Ejer2 iglist::[Integer]->[Integer]->Bool iglist [] [] = True iglist [] (a) = False iglist (a) [] = False iglist (a:xs) (b:ys) = if a==b then (iglist(xs) (ys)) else False concatenar::[Integer]->[Integer]->[Integer] concatenar [] [] = [] concatenar [] (a) = (a) concatenar (a) [] = (a) concatenar (a:xs) (b:ys) = a:concatenar (xs) (b:ys) a=[1,2,3,5] b=[1,2,3] c=[1,2,5,3] ordenada::[Integer]->Bool ordenada []=True ordenada [a] = True ordenada (a:b:xs) = if (aInteger largo []=0 largo (a:xs)=1+largo(xs) --Practico 8 Ejer 5f --Ejemplo: posicion [2,3,5,8,4,9] 4 devuelve 5 -- posicion [5,3,8] 9 devuelve 0 posicion :: [Int] -> Int -> Int posicion [ ] a = 0 posicion (a: xs) b = if (esta (a:xs) b == 0) then 0 else (if a /= b then 1 + posicion (xs) b else 1) esta :: [Int] -> Int -> Int esta [ ] a = 0 esta (a: xs) b = if a /= b then 0 + esta (xs) b else 1 + esta (xs) b --Ejer 5g Mapear mapear::(Int->Int)->[Int]->[Int] mapear funcion [] = [] mapear funcion (a:xs) = (funcion a) : mapear funcion(xs) --Auxiliares suma5::Int->Int suma5 a=a+5 doble::Int->Int doble a=a*2 --Ejer Filtrar filtrar ::(Int->Bool)->[Int]->[Int] filtrar funcion []=[] filtrar funcion (a:xs) = if (funcion a) then (a:filtrar funcion (xs)) else (filtrar funcion (xs)) --Auxiliar es_par::Int->Bool es_par a = mod a 2==0 --- Se agradece al estudiante Juan Pablo Albano del grupo del Interior de matemática 1 por enviar estos ejercicios.