-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path20150407.hs
More file actions
83 lines (66 loc) · 1.97 KB
/
20150407.hs
File metadata and controls
83 lines (66 loc) · 1.97 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
data Shape = Circle Float
|Rectangle Float Float
area :: Shape -> Float
area (Circle r) = pi*(r)^2
area (Rectangle a h) = a*h
data Dias = Segunda Int [String]
| Terça Int [String]
| Quarta Int [String]
| Quinta Int [String]
| Sexta Int [String]
| Sabado
| Domingo
terca :: Dias
quinta :: Dias
terca = Terça 2 ["PLC", "Bla"]
quinta = Quinta 2 ["Bla","Bla","PLC", "Bla"]
existe :: [String] -> String -> Bool
existe ll s
|(head[x | x<- ll , x == s]) /= "" = True
|otherwise = False
fimSemana :: Dias -> Bool
fimSemana Sabado = True
fimSemana Domingo = True
fimSemana _ = False
aulaPLC:: Dias -> Bool
aulaPLC Domingo = False
aulaPLC Sabado = False
aulaPLC (Segunda h ll) = existe ll "PLC"
aulaPLC (Terça h ll) = existe ll "PLC"
aulaPLC (Quarta h ll) = existe ll "PLC"
aulaPLC (Quinta h ll) = existe ll "PLC"
aulaPLC (Sexta h ll) = existe ll "PLC"
{-Modifique o tipo Tree para que valores desse tipo sejam
comparáveis (para saber se são iguais) e que seja possível
transformá-los em Strings -}
data Tree t = NilT
|Node t (Tree t) (Tree t) deriving (Eq, Show)
data Expr = Lit Int
|Add Expr Expr
|Sub Expr Expr
showExpr :: Expr -> String
showExpr (Lit n) = show n
showExpr (Add exprA exprB) = showExpr(exprA) ++ "+" ++ showExpr(exprB)
showExpr (Add exprA exprB) = showExpr(exprA) ++ "-" ++ showExpr(exprB)
data List t = Nil
|Cons t (List t)
toList :: List t -> [t]
toList Nil = []
toList (Cons a as) = a:toList(as)
fromList :: [t] -> List t
fromList [] = Nil
fromList (a:as) = Cons a (fromList as)
depth :: Tree t -> Int
depth NilT = 0
depth (Node r a b) = 1 + max (depth(a)) (depth(b))
collapse :: Tree t -> [t]
collapse NilT = []
collapse (Node r a b) = collapse a ++ [r] ++ collapse b
bfs :: Tree t -> t -> Bool
bfs NilT _ = False
bfs (Node t l r) n
| t == n = True
| otherwise = (bfs l n) || (bfs r n)
mapTree :: (t -> u) -> Tree t -> Tree u
mapTree _ NilT = NilT
mapTree f (Node t l r) = Node (f t) (mapTree f l) (mapTree f r)