Guest User

Untitled

a guest
Aug 13th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --LISTA 03
  2. --1
  3. lista03soma :: [Int]->Int
  4. lista03soma (x:xs) | xs == [] = x
  5.                    | otherwise = x + (lista03soma xs)
  6. --2                
  7. lista03mult :: [Int]->Int
  8. lista03mult (x:xs) | xs == [] = x
  9.                    | otherwise = x * (lista03mult xs)
  10.  
  11. --3                
  12. perfeito :: Int->Bool
  13. perfeito n |(sum[x|x<-[1..n-1], mod n x == 0]) == n = True
  14.            |otherwise = False
  15.  
  16. {--perfeitorec :: Int->Bool
  17. perfeitorec n | mod n
  18. --}
  19.  
  20. --4
  21. tirarrep :: [Int]->[Int]
  22. tirarrep [] = []
  23. tirarrep [h] = [h]
  24. tirarrep (h:t) = h:(tirarrep [x|x<-(h:t), x /= h])
  25.  
  26. --5
  27. elemOrdem :: Int->[Int]->[Int]
  28. elemOrdem n [] = [n]
  29. elemOrdem n (x:xs) | n <= x = n:(x:xs)
  30.                    |otherwise = x:(elemOrdem n xs)
  31.              
  32. ordemlistas :: [Int]->[Int]->[Int]
  33. ordemlistas (x:xs) [] = (x:xs)
  34. ordemlistas [] (y:ys) = (y:ys)
  35. ordemlistas (x:xs) (y:ys) = ordemlistas xs(elemOrdem x (y:ys))
  36.  
  37. --6
  38. verifordem :: [Int]->Bool
  39. verifordem [] = True
  40. verifordem [x] = True
  41. verifordem (x:xs) | x > (head xs) = False
  42.                   | otherwise = verifordem xs
  43.                  
  44. --7
  45. maiorelem :: [Int]->Int
  46. maiorelem [] = 0
  47. maiorelem [x] = x
  48. maiorelem (x:xs) | x > head xs = (maiorelem (x:(tail xs)))
  49.                | x <= head xs = maiorelem xs
  50.  
  51. --8
  52. pertence :: Int->[Int]->Bool
  53. pertence y [] = False
  54. pertence y (x:xs) | y == x = True
  55.                 | otherwise = pertence y xs
  56.  
  57. conjunto :: [Int]->[Int]->[Int]
  58. conjunto (x:xs) [] = (x:xs)
  59. conjunto [] (y:ys) = (y:ys)
  60. conjunto (x:xs) (y:ys) | (pertence x (y:ys)) == True = (conjunto xs (y:ys))
  61.                        | otherwise = (x:(conjunto xs (y:ys)))
  62.                        
  63. --9
  64.  
  65. mseg :: String->[String]
  66. mseg [] = []
  67. mseg (x:xs) = [(x:xs)]++(mseg (take (length xs) (x:xs)))
  68.  
  69.  
  70. qegs :: String->[String]
  71. qegs [] = [[]]
  72. qegs (x:xs) = ((mseg (x:xs))++(qegs xs))
  73.  
  74. segs :: String->[String]
  75. segs (x:xs) = reverse(qegs (x:xs))
  76.  
  77. --10
  78.  
  79.            
  80. apagar :: [(Float,Float)]->(Float,Float)->[(Float,Float)]
  81. apagar (x:xs) t | quant x == quant t && valor x == valor t = xs
  82.                 | otherwise = [x]++apagar xs t
  83.            
  84. quant (a,b) = a
  85. valor (a,b) = b
  86.  
  87. preco grao = (valor grao)/(quant grao)
  88.  
  89.  
  90. maiscaro :: [(Float,Float)]->(Float,Float)
  91. maiscaro [x] = x
  92. maiscaro (x:xs) | preco x > (preco (head xs)) = maiscaro ([x]++(tail xs))
  93.                 | preco x < (preco (head xs)) = (maiscaro xs)
  94.                
  95.  
  96. posicao :: [(Float,Float)]->(Float,Float)->Int
  97. posicao [x] grao = 1
  98. posicao (x:xs) grao | quant x == quant grao && valor x== valor grao = 1
  99.                     | otherwise = 1 + (posicao xs grao)
  100.    
  101.  
  102. --aqui é 10 de verdade
  103. vmax :: [(Float,Float)]->Float->Float
  104. vmax [] n = 0
  105. vmax graos 0 = 0
  106. vmax [] 0 = 0
  107. vmax graos n | quant (maiscaro graos) >= n = n*(preco(maiscaro graos))
  108.              | quant (maiscaro graos) < n = valor(maiscaro graos)+ (vmax (apagar graos (maiscaro graos)) (n-(quant(maiscaro graos))))
Add Comment
Please, Sign In to add comment