Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --LISTA 03
- --1
- lista03soma :: [Int]->Int
- lista03soma (x:xs) | xs == [] = x
- | otherwise = x + (lista03soma xs)
- --2
- lista03mult :: [Int]->Int
- lista03mult (x:xs) | xs == [] = x
- | otherwise = x * (lista03mult xs)
- --3
- perfeito :: Int->Bool
- perfeito n |(sum[x|x<-[1..n-1], mod n x == 0]) == n = True
- |otherwise = False
- {--perfeitorec :: Int->Bool
- perfeitorec n | mod n
- --}
- --4
- tirarrep :: [Int]->[Int]
- tirarrep [] = []
- tirarrep [h] = [h]
- tirarrep (h:t) = h:(tirarrep [x|x<-(h:t), x /= h])
- --5
- elemOrdem :: Int->[Int]->[Int]
- elemOrdem n [] = [n]
- elemOrdem n (x:xs) | n <= x = n:(x:xs)
- |otherwise = x:(elemOrdem n xs)
- ordemlistas :: [Int]->[Int]->[Int]
- ordemlistas (x:xs) [] = (x:xs)
- ordemlistas [] (y:ys) = (y:ys)
- ordemlistas (x:xs) (y:ys) = ordemlistas xs(elemOrdem x (y:ys))
- --6
- verifordem :: [Int]->Bool
- verifordem [] = True
- verifordem [x] = True
- verifordem (x:xs) | x > (head xs) = False
- | otherwise = verifordem xs
- --7
- maiorelem :: [Int]->Int
- maiorelem [] = 0
- maiorelem [x] = x
- maiorelem (x:xs) | x > head xs = (maiorelem (x:(tail xs)))
- | x <= head xs = maiorelem xs
- --8
- pertence :: Int->[Int]->Bool
- pertence y [] = False
- pertence y (x:xs) | y == x = True
- | otherwise = pertence y xs
- conjunto :: [Int]->[Int]->[Int]
- conjunto (x:xs) [] = (x:xs)
- conjunto [] (y:ys) = (y:ys)
- conjunto (x:xs) (y:ys) | (pertence x (y:ys)) == True = (conjunto xs (y:ys))
- | otherwise = (x:(conjunto xs (y:ys)))
- --9
- mseg :: String->[String]
- mseg [] = []
- mseg (x:xs) = [(x:xs)]++(mseg (take (length xs) (x:xs)))
- qegs :: String->[String]
- qegs [] = [[]]
- qegs (x:xs) = ((mseg (x:xs))++(qegs xs))
- segs :: String->[String]
- segs (x:xs) = reverse(qegs (x:xs))
- --10
- apagar :: [(Float,Float)]->(Float,Float)->[(Float,Float)]
- apagar (x:xs) t | quant x == quant t && valor x == valor t = xs
- | otherwise = [x]++apagar xs t
- quant (a,b) = a
- valor (a,b) = b
- preco grao = (valor grao)/(quant grao)
- maiscaro :: [(Float,Float)]->(Float,Float)
- maiscaro [x] = x
- maiscaro (x:xs) | preco x > (preco (head xs)) = maiscaro ([x]++(tail xs))
- | preco x < (preco (head xs)) = (maiscaro xs)
- posicao :: [(Float,Float)]->(Float,Float)->Int
- posicao [x] grao = 1
- posicao (x:xs) grao | quant x == quant grao && valor x== valor grao = 1
- | otherwise = 1 + (posicao xs grao)
- --aqui é 10 de verdade
- vmax :: [(Float,Float)]->Float->Float
- vmax [] n = 0
- vmax graos 0 = 0
- vmax [] 0 = 0
- vmax graos n | quant (maiscaro graos) >= n = n*(preco(maiscaro graos))
- | quant (maiscaro graos) < n = valor(maiscaro graos)+ (vmax (apagar graos (maiscaro graos)) (n-(quant(maiscaro graos))))
Add Comment
Please, Sign In to add comment