-
Notifications
You must be signed in to change notification settings - Fork 0
/
april2023.hs
137 lines (116 loc) · 3.07 KB
/
april2023.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import Data.Char
import Test.HUnit
import Graphics.Rendering.Chart.Easy (dimgray)
{-
1
a
Char
String
[Char]ó String
No es válido, sólo tiene une elemento
b
volShere :: Float -> Float
scalarMult :: Num a => a -> (a,a) -> (a,a)
firstAndLast :: [a] -> (a,a)
isTautology :: Eq a => a -> a -> a -> Bool
2
Si
No
Depende de la implementación
Si
Si
Depende de la implementación
Si
Si
Si
Si
No
No
Si
3
19
4
(1,4)
2
[(1,2,3),(4,5,6)]
[7]
[[2,1]]
3
circulo :: Int -> Int
circulo n = length [(x,y) | x <- [0..n], y <- [0..n], x*x+y*y<n*n]
4
divisors :: Int -> [Int]
divisors n = [x | x <- [1..n], isDivisor x]
where isDivisor y = n `mod` y == 0
-}
--5
--a
toNumber :: Char -> Int
toNumber c = if isDigit c
then digitToInt c
else error "Not a number"
--b
numRoots :: Float -> Float -> Float -> Int
numRoots a b c | delta < 0 = 0
| delta == 0 = 1
| otherwise = 2
where delta = b**2 -4*a*c
--c
secureDiv :: Float -> Float -> Float
secureDiv _ 0 = error "Division by zero"
secureDiv x y = x / y
--6
--a
triangleArea :: Float -> Float -> Float
triangleArea = \b -> \h-> (b*h) / 2
--b
addPairs :: Num a => (a,a) -> (a,a) -> (a,a)
addPairs = \(x,y) -> \(z,w) -> (x+z, y+w)
--7
--a
func :: [Int] -> [Int]
func ns = [n | n <- ns, odd n && n /= 5]
--b
divisors :: Int -> [Int]
divisors n = [x | x <- [1..n], n `mod` x == 0]
perfects :: Int -> [Int]
perfects n = [x | x <- [1..n], isPerfect x]
where isPerfect x = x == sum(init(divisors x))
testPerfects :: Test
testPerfects = test [
"Invalid value" ~: perfects (-1) ~?= [],
"No perfects" ~: perfects 1 ~?= [],
"Perfects" ~: perfects 10 ~?= [6]
]
{-8
a
Da el doble de elementos de la tripla que sean pares
b
Cambiar el 2 por 1
-}
informaticos :: [(String,String,String,Int)]
informaticos = [("Lovelace","Ada","UK",1815),
("Hopper","Grace","USA",1906),
("Backus","John","USA",1924),
("Minsky","Marvin","USA",1927),
("McCarthy","John","USA",1927),
("Dijkstra","Edsger W.","Netherlands",1930),
("Knuth","Donald","USA",1938),
("Leslie","Lamport","USA",1941),
("Ritchie","Dennis M.","USA",1941),
("Kernighan","Brian W.","Canada",1942),
("Cerf","Vinton","USA",1943),
("Thompson","Ken","USA",1943),
("Tanenbaum","Andrew S.","USA",1944),
("Stallman","Richard","USA",1953),
("Berners-Lee","Tim","UK",1955),
("van Rossum","Guido","Netherlands",1956),
("Fowler","Martin","UK",1963),
("Torvalds","Linus","Finland",1969)
]
surnames :: [(String,String,String,Int)] -> [String]
surnames db = [s | (s,_,_,_) <- db]
bornIn :: Int -> [(String,String,String,Int)]-> [(String, String)]
bornIn y db = [(s, n) | (s,n,_,x) <- db, x == y]
--10
--Crea una copia de un repositorio existente en un nuevo directorio