Skip to content

Instantly share code, notes, and snippets.

@washingtonsoares
Created May 26, 2016 00:57
Show Gist options
  • Save washingtonsoares/8906cf9ea63c53274f583d0fc88b02d1 to your computer and use it in GitHub Desktop.
Save washingtonsoares/8906cf9ea63c53274f583d0fc88b02d1 to your computer and use it in GitHub Desktop.
-- Washington Soares Braga
-- Exercicio 01
-- Washington
-- Braga
-- str1 > (tail str2)
-- True
-- (tail str1) ++ str2
-- "ashingtonbraga"
-- head (tail (tail str1))
-- 's'
-- fst (head str1 , tail str2)
-- 'w'
-- 'b' ++ str1
-- erro
-- snd (head str1 , tail str2)
-- "raga"
-- "1,2,3" ++ str1
-- "1,2,3washington"
-- (head (tail str2), tail str1)
-- ('r',"ashington")
-- head str1 ++ str1
-- erro
-- str2 ++ [1,2,3,7]
-- erro
-- [’p’] ++ str1 ++ str2
-- "pwashingtonbraga"
-- Exercicio 02
somatorio :: [(Integer, Integer)] -> Integer
somatorio [] = 0
somatorio (p:r) = (fst(p)^snd(p)) + somatorio(r)
-- Exercicio 03
h :: Int -> Int -> Int
h m n
| m ==0 = n+1
| m /= 0 && n == 0 = h (m-1) 1
| m /= 0 && n /= 0 = h(m-1) (h m (n-1))
| otherwise = 0
g :: Int -> Int
g n
| n <= 0 = 0
| otherwise = g(n-1) + 2 * n -1
h2 :: Int -> Int
h2 n
| n == 1 = 1
| n > 1 = 2 * h2(n-1)+1
| otherwise = 0
-- Exercicio 04
--a
--Implementacao de cada funcao contendo sua assinatura.
-- 1 -
f1 :: [Int] -> Int
f1 [e] = e
f1 (p:s:r)
| p > s = f1 (s:r)
| otherwise = f1 (p:r)
-- 2 -
f2 :: [Int] -> [Int]
f2 [] = []
f2 (p:s:r) = s : f2 r
-- 3 -
f3 :: [Int] -> [Bool]
f3 [] = []
f3 (p:r)
| p > 0 = True : f3 r
| otherwise = False : f3 r
-- 4 -
f4 :: [Int] -> [Int]
f4 [] = []
f4 (p:r) = p : p : f4 r
--b
-- Passo a passo das funcoes do item 'a' (lembre-se de comentar as linhas com --)
-- 1
-- (0, 7, 1, 1)
-- f1(0, 7, 1, 1)
-- f1(0,1,1)
-- f1(0,1)
-- f1(0)
-- 0
-- 2
-- f2(0, 7, 1, 1)
-- 7:f2(1, 1)
-- 7:1:f2([])
-- [7, 1]
-- 3
-- f3(0, 7, 1, 1)
-- f3(0, 7, 1, 1)
-- False:f3(7, 1, 1)
-- True:f3(1, 1)
-- True:f3(1)
-- True:f3([])
-- [False, True, True, True]
-- 4
-- f4(0, 7, 1, 1)
-- 0:0:f4(7, 1, 1)
-- 0:0:7:7:f4(1, 1)
-- 0:0:7:7:1:1:f4(1)
-- 0:0:7:7:1:1::1:1f4([])
-- [0,0,7,7,1,1,1,1]
-- Exercicio 05
remover :: Char -> String -> String
remover c [] = []
remover c (pc:rc)
| c == pc = remover c rc
| otherwise = pc : remover c rc
pertence :: Char -> String -> Bool
pertence c [] = False
pertence c (p:r) = if(length (p:r) == length (remover c (p:r)))
then False
else
True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment