-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_08mar.hs
71 lines (49 loc) · 1.48 KB
/
03_08mar.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
offset :: Int
offset = fromEnum 'A' - fromEnum 'a'
maiuscula :: Char -> Char
maiuscula ch = toEnum (fromEnum ch + offset)
ehDigito :: Char -> Bool
ehDigito ch = ('0' <= ch) && (ch <= '9')
ehMinuscula :: Char -> Bool
ehMinuscula ch = ('a' <= ch) && (ch <= 'z')
-- Tuplas
primeiro :: (Int, Int) -> Int
--primeiro (x,y) = x
primeiro (x,_) = x
segundo :: (Int, Int) -> Int
segundo (x,y) = y
primeiroTripla :: (Int, Int, Int) -> Int
primeiroTripla (x, y, z) = x
shift :: ((Int,Int), Int) -> (Int,(Int,Int))
shift ((x, y), z) = (x, (y, z))
extraiValor :: (Bool,(Int,Bool),Char) -> Char
--extraiValor (b1 , (i, b2) , c) = c
extraiValor (_ , _ , c) = c
-- Sinonimos de tipos
--type Identificador = tipo
type ParInteiro = (Int,Int)
primeiroParInteiro :: ParInteiro -> Int
primeiroParInteiro (x,y) = x
type Nome = String
type Idade = Int
type Telefone = Int
type Pessoa = (Nome, Idade, Telefone)
nome :: Pessoa -> Nome
nome (n, idd, tlf) = n
-- Equacao do segundo grau
umaRaiz :: Float -> Float -> Float -> Float
umaRaiz a b c = -b / (2 * a)
duasRaizes :: Float -> Float -> Float -> (Float, Float)
duasRaizes a b c = (d - e, d + e)
where
d = -b / (2*a)
e = sqrt( b^2 - 4.0 * a * c) / (2.0 * a)
raizes :: Float -> Float -> Float -> String
raizes a b c
| b ^ 2 == 4.0 * a * c = show (umaRaiz a b c)
| b ^ 2 > 4.0 * a * c = show f ++ " " ++ show s
| otherwise = "nao hah raizes"
where
(f, s) = (duasRaizes a b c)
-- f = fst (duasRaizes a b c)
-- s = snd (duasRaizes a b c)