Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Introduccion Algoritmos
Introduccion Algoritmos
Introducción
11/03/2015
if (l < h) {'
t = a[l];'
a[l] = a[h];'
a[h] = t;'
}'
}while (l < h);'
t = a[l];'
a[l] = a[hi];'
a[hi] = t;'
foo( a, lo, l-1 );'
foo( a, l+1, hi );'
}'
}'
foo [ ] = [ ]
foo (x : xs) = foo menor +
+ [x ] +
+ foo mayor
where
menor = [y | y ← xs, y < x ]
mayor = [y | y ← xs, y > x ]
a =b+c
where
b=1
c=2
d =a +2
abs n | n > 0 =n
| otherwise = −n
abs n | n > 0 =n
| otherwise = −n
signum n | n < 0 = − 1
|n≡0=0
| otherwise = 1
abs n | n > 0 =n
| otherwise = −n
signum n | n < 0 = − 1
|n≡0=0
| otherwise = 1
otherwise = True
fst :: (a, b) → a
fst (x , ) = x
snd :: (a, b) → b
snd ( , y) = y
fst :: (a, b) → a
fst (x , ) = x
snd :: (a, b) → b
snd ( , y) = y
fst :: (a, b) → a
fst (x , ) = x
snd :: (a, b) → b
snd ( , y) = y
[1, 2, 3, 4] ≡ 1 : (2 : (3 : (4 : [ ])))
[1, 2, 3, 4] ≡ 1 : (2 : (3 : (4 : [ ])))
head :: [a ] → a
head (x : ) = x
tail :: [a ] → [a ]
tail ( : xs) = xs
[1, 2, 3, 4] ≡ 1 : (2 : (3 : (4 : [ ])))
head :: [a ] → a
head (x : ) = x
tail :: [a ] → [a ]
tail ( : xs) = xs
{x2 |x ∈ {1 . . . 5}}
[x ↑ 2 | x ← [1 . . 5]]
concat :: [[a ]] → [a ]
concat xss = [x | xs ← xss, x ← xs ]
concat :: [[a ]] → [a ]
concat xss = [x | xs ← xss, x ← xs ]
[x | x ← [1 . . 10], even x ]
[x | x ← [1 . . 10], even x ]
[x | x ← [1 . . 10], even x ]
La función zip, mapea dos listas a una lista con los pares de
elementos correspondientes
La función zip, mapea dos listas a una lista con los pares de
elementos correspondientes
La función zip, mapea dos listas a una lista con los pares de
elementos correspondientes
> [x ↑ 2 | x ← [1 . . 10]]
[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
> rangeof 3 7 [x ↑ 2 | x ← [1 . . 10]]
[16, 25, 36, 49, 64]
length :: [a ] → Int
length [ ] =0
length (x : xs) = 1 + length xs
> zigzag [(1, 2), (3, 4), (5, 6), (7, 8)]
[1, 4, 5, 8]
qsort :: Ord a ⇒ [a ] → [a ]
qsort [ ] = []
qsort (x : xs) = qsort chicos ++ [x ] +
+ qsort grandes
where chicos = [a | a ← xs, a 6 x ]
grandes = [b | b ← xs, b > x ]
> :t Circle
Circle :: Float → Shape
> :t Rect
Rect :: Float → Float → Shape