Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created March 2, 2010 07:54
Show Gist options
  • Save jsoffer/319249 to your computer and use it in GitHub Desktop.
Save jsoffer/319249 to your computer and use it in GitHub Desktop.
data Op = UD | UTP | UTI | MD | MTP | MTI deriving (Show, Eq)
-- la lista guarda las claves de las operaciones que van pasando
paso :: ([Op], Integer, Integer, Integer) -> ([Op], Integer, Integer, Integer)
paso (l, r, n, 0) = (l, r, n, 0)
-- paso (1, 2, n) = paso (2, 3, n) -- directo (3x+1)/2
paso (xs, 1, 2, n) = paso (UD:xs, -1, 3, n+1) -- moviendo 3 a lado derecho
paso (xs, 1, 3, n)
| even n = paso (UTP:xs, 1, 2, 3 * (div n 2)) -- convierto 3*2*k en 2*3*k
-- | odd n = paso (2, 3, div (n-1) 2) -- muevo un 3 al lado izquierdo, divido
| odd n = paso (UTI:xs, -1, 3, (div (n-1) 2) + 1) -- moviendo 3 a lado derech0
paso (xs, -1, 2, n) = paso (MD:xs, -1, 3, n) -- directo
paso (xs, -1, 3, n)
| even n = paso (MTP:xs, -1, 2, 3 * (div n 2)) -- convierto 3*2*k en 2*3*k
| odd n = paso (MTI:xs, 1, 3, div (n-1) 2) -- muevo un 3 al lado izquierdo, divido
prueba :: Integer -> [Op]
prueba x = lista where
(lista, _, _, _) = paso ([], -1, 2, x)
iguales :: (Eq a) => [a] -> [a] -> [a]
iguales [] _ = []
iguales _ [] = []
iguales (x:xs) (y:ys) = if x == y then x : iguales xs ys else []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment