-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20150409.hs
More file actions
87 lines (61 loc) · 1.9 KB
/
20150409.hs
File metadata and controls
87 lines (61 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
--slide 7
raizQ :: [Float] -> [Float]
raizQ ll = map (sqrt) ll
posicaoAlfabeto :: String -> [(Char, Int)] -> [Int]
posicaoAlfabeto ll base = map (charToInt base) ll
mapA :: (a->b) -> [a] -> [b]
mapA func ll = [func x | x<-ll]
--slide 14
member :: Eq t => t -> [t] ->Bool
member e l = foldr (||) False (map (==e) l)
unionA :: Eq t => [t] -> [t] -> [t]
unionA ll1 [] = ll1
unionA [] ll2 = ll2
unionA ll1 ll2 = foldr (++) ll2 [ll1]
--slide 15
base :: [(Char, Int)]
base = zip ['a'..'z'] [1..26]
charToInt:: [(Char, Int)] -> Char -> Int
charToInt (x:xs) a
|(a == fst x) = snd (x)
|otherwise = charToInt xs a
stringToInt :: [(Char, Int)] -> String -> Int
stringToInt base s = foldr (+) 0 (map (charToInt base) s)
fun :: [String] -> [(Char, Int)] -> [Int]
fun [] base = []
fun (a:as) base = [(stringToInt base a)] ++ (fun as base)
--slide 16
data Tree a = EmptyTree
| Node a (Tree a) (Tree a) deriving (Show, Read, Eq)
insert :: (Ord a) => Tree a -> a -> Tree a
insert EmptyTree x = Node x EmptyTree EmptyTree
insert (Node a l r) x
|x == a = Node x l r
|x > a = Node a l (insert r x)
|x < a = Node a (insert l x) r
createTree :: (Ord t) => [t]-> (Tree t -> t -> Tree t) -> Tree t
createTree [] func = EmptyTree
--createTree (a:as) func = foldr (func) a (as)
--slide 19
--outra definição >>>filter p l = [a | a <- l, p a]
filterA :: (t->Bool) -> [t] -> [t]
filterA f [] = []
filterA f (a:as)
|f a = a:filterA f as
|otherwise = filterA f as
funMenor :: [Int] -> [Int]
funMenor ll = filterA (>0) ll
--slide 20
exist :: Int -> [Int] -> Bool
exist n [] = False
exist n (a:as)
| n == a = True
| otherwise = exist n as
existe :: [Int] -> [Int] -> [Bool]
existe [] ll2 = [False]
existe ll1 [] = [False]
existe (a:as) ll2
|(exist (a) (ll2)) = (True:(existe (as) (ll2 )))
| otherwise = existe (as) (ll2)
--inter :: [Int] -> [Int] -> [Int]
--inter a b = filter (&&) (existe a b)