-
Notifications
You must be signed in to change notification settings - Fork 0
/
clase5.hs
65 lines (50 loc) · 2.24 KB
/
clase5.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
pertenece :: Integer -> [Integer] -> Bool
pertenece n [] = False
pertenece n l | head l == n = True
| otherwise = pertenece n (tail l)
hayRepetidos :: [Integer] -> Bool
hayRepetidos [] = False
hayRepetidos l | pertenece (head l) (tail l) = True
| otherwise = hayRepetidos (tail l)
menores :: Integer -> [Integer] -> [Integer]
menores n [] = []
menores n l | p < n = [p] ++ menores n (tail l) where p = head l
menores n l | otherwise = menores n (tail l)
quitar :: Integer -> [Integer] -> [Integer]
quitar n [] = []
-- quitar n l | head l == n = quitar (tail l)
quitar n l | head l == n = tail l
| otherwise = [head l] ++ quitar n (tail l)
maximo :: [Integer] -> Integer
maximo l | length (menores p l) == length l - 1 = p where p = head l
maximo l | otherwise = maximo (tail l)
enBase :: Integer -> Integer -> [Integer]
enBase d 0 = []
enBase d n = enBase d (div n d) ++ [mod n d]
deBase :: Integer -> [Integer] -> Integer
deBase d [] = 0
deBase d l = (head l) * d ^ (length l - 1) + deBase d (tail l)
capicuaPara :: [Integer] -> [Integer]
capicuaPara l | reverse l == l = l
capicuaPara l | otherwise = capicuaPara (enBase 10 (deBase 10 l + deBase 10 (reverse l)))
cambioBase :: Integer -> Integer -> [Integer] -> [Integer]
cambioBase b1 b2 l = enBase b2 (deBase b1 l)
esASC :: [Integer] -> Bool
esASC [] = True
esASC l | length l == 1 = True
esASC l | head l < head (tail l) && esASC (tail l) = True
esASC l | otherwise = False
rmRepetidos :: [Integer] -> [Integer]
rmRepetidos l | not (hayRepetidos l) = l
rmRepetidos l | pertenece (head l) (tail l) = rmRepetidos (tail l)
rmRepetidos l | otherwise = [head l] ++ rmRepetidos (tail l)
rmRepetidosPrimera :: [Integer] -> [Integer]
rmRepetidosPrimera l = reverse (rmRepetidos (reverse l))
unionListasOrdenadas :: [Integer] -> [Integer] -> [Integer]
unionListasOrdenadas a [] = a
unionListasOrdenadas [] b = b
unionListasOrdenadas a b | ap < bp = [ap] ++ [bp] ++ unionListasOrdenadas (tail a) (tail b) where ap = head a ; bp = head b
unionListasOrdenadas a b | otherwise = [bp] ++ [ap] ++ unionListasOrdenadas (tail a) (tail b) where ap = head a ; bp = head b
ordenarLista :: [Integer] -> [Integer]
ordenarLista [] = []
ordenarLista l = ordenarLista (quitar m l) ++ [m] where m = maximo l