# Reducción de repeticiones consecutivas

Definir la función

` reducida :: Eq a => [a] -> [a]`

tal que (reducida xs) es la lista obtenida a partir de xs de forma que si hay dos o más elementos idénticos consecutivos, borra las repeticiones y deja sólo el primer elemento. Por ejemplo,

``` ghci> reducida "eesssooo essss toodddooo" "eso es todo"```

Nota: Basado en el ejercicio Apaxiaaaaaaaaaaaans! de Kattis.

#### Soluciones

```import Data.List (group)   -- 1ª solución (por recursión): reducida1 :: Eq a => [a] -> [a] reducida1 [] = [] reducida1 (x:xs) = x : reducida1 (dropWhile (==x) xs)   -- 2ª solución (por comprensión): reducida2 :: Eq a => [a] -> [a] reducida2 xs = [x | (x:_) <- group xs]   -- 3ª solución (sin argumentos): reducida3 :: Eq a => [a] -> [a] reducida3 = map head . group```
Medio

## 13 soluciones de “Reducción de repeticiones consecutivas”

1. fraferpoy
```import Data.List   reducida :: Eq a => [a] -> [a] reducida = concat . map nub . group```
• eliguivil

Lo anterior puede simplificarse a

```reducida :: Eq a => [a] -> [a] reducida = map head . group```
2. ignareeva
```import Data.List   reducida :: Eq a => [a] -> [a] reducida xs = map head \$ group xs```
3. javcancif
```listasinx :: Eq a => [a] -> [a] listasinx [] = [] listasinx xs = dropWhile (==x) xs where x = head xs   reducida :: Eq a => [a] -> [a] reducida [] = [] reducida [x] = [x] reducida (x:y:xs) | x == y = x : reducida (listasinx (y:xs)) | otherwise = x : reducida (y:xs)```
4. marlobrip
```import Data.List   reducida :: Eq a => [a] -> [a] reducida = concat . map nub . group```
5. glovizcas
```reducida :: Eq a => [a] -> [a] reducida = concatMap nub . group```
6. antdursan
```reducida :: Eq a => [a] -> [a] reducida xs = aux zs where aux [] = [] aux [x] = [x] aux (x:y:xs) | x == y = x : (reducida xs) | otherwise = x : (reducida (y:xs)) zs = aux xs```
7. enrnarbej
```reducida :: Eq a => [a] -> [a] reducida xs = head <\$> group xs```
8. javcancif
```listasinx :: Eq a => [a] -> [a] listasinx [] = [] listasinx xs = dropWhile (==x) xs where x = head xs   reducida :: Eq a => [a] -> [a] reducida [] = [] reducida [x] = [x] reducida (x:y:xs) | x == y = x : reducida (listasinx (y:xs)) | otherwise = x : reducida (y:xs)```
9. natalia
```reducida [x] =[x] reducida (x:y:xs) | x==y = m (y:xs) | otherwise = x:m (y:xs)```
10. albcercid
```reducida :: Eq a => [a] -> [a] reducida = map head.group```
11. alvfercen
```reducida :: Eq a => [a] -> [a] reducida xs = concat \$ map (nub) (group xs)```
12. marmerzaf - natmarmar2
```reducida1 [] = [] reducida1 (x : y : xs) | x == y = x : dropWhile (==x) (reducida1 (xs)) | otherwise = x:y: dropWhile (==y) (reducida1 xs)```

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.