-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02_01mar.hs
86 lines (67 loc) · 1.6 KB
/
02_01mar.hs
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
-- Tipos
exOr :: Bool -> Bool -> Bool
exOr x y = (x || y) && not (x && y)
exOrCasamPadrao :: Bool -> Bool -> Bool
exOrCasamPadrao True x = not x
exOrCasamPadrao False x = x
mAnd :: Bool -> Bool -> Bool
mAnd True True = True
mAnd True False = False
mAnd False True = False
mAnd False False = False
mAnd2 :: Bool -> Bool -> Bool
mAnd2 True True = True
mAnd2 True False = False
mAnd2 False _ = False
mAnd3 :: Bool -> Bool -> Bool
mAnd3 True b = b
mAnd3 _ _ = False
mAnd4 :: Bool -> Bool -> Bool
mAnd4 True True = True
mAnd4 _ _ = False
-- Funcoes recursivas
fatorial :: Int -> Int
fatorial 0 = 1 -- Caso base
fatorial n = n * fatorial (n - 1) -- Caso recursivo
vendas :: Int -> Int
vendas 0 = 3
vendas 1 = 4
vendas 2 = 20
vendas 3 = 0
vendas 4 = 9
vendas 5 = 30
totalVendas :: Int -> Int
totalVendas n
| (n == 0) = vendas 0
| otherwise = vendas n + totalVendas(n-1)
totalVendas2 :: Int -> Int
totalVendas2 0 = vendas 0
totalVendas2 n = vendas n + totalVendas2 (n-1)
maxi :: Int -> Int -> Int
maxi x y = if x >= y
then x
else y
maiorVenda :: Int -> Int
maiorVenda n
| (n == 0) = vendas 0
| otherwise = maxi (vendas n) (maiorVenda (n-1))
{-
vendasZero :: Int -> Bool
vendasZero n =
if (vendas n == 0)
then True
else vendasZero (n-1)
-}
vendasZero2 :: Int -> Bool
vendasZero2 n
| (vendas n == 0) = True
| (n == 0) = False
| otherwise = vendasZero2(n-1)
vendaNula :: Int -> Bool
vendaNula n
| (vendas n == 0) = True
| otherwise = False
vendasZero3 :: Int -> Bool
vendasZero3 n
| (n == 0) = vendaNula 0
| otherwise = vendaNula n || vendasZero3(n-1)