Permutación de elementos consecutivos
1 2 3 4 5 6 7 |
-- Definir la función -- permutaConsecutivos :: [a] -> [a] -- tal que (permutaConsecutivos xs) es la lista obtenida permutando los -- elementos consecutivos de xs. Por ejemplo, -- permutaConsecutivos [1..8] == [2,1,4,3,6,5,8,7] -- permutaConsecutivos [1..9] == [2,1,4,3,6,5,8,7,9] -- permutaConsecutivos "simplemente" == "ispmelemtne" |
Soluciones
1 2 3 |
permutaConsecutivos :: [a] -> [a] permutaConsecutivos (x:y:zs) = y : x : permutaConsecutivos zs permutaConsecutivos xs = xs |
3 Comentarios