Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created March 3, 2010 03:09
Show Gist options
  • Save jsoffer/320264 to your computer and use it in GitHub Desktop.
Save jsoffer/320264 to your computer and use it in GitHub Desktop.
data Op = UD | UTP | UTI | MD | MTP | MTI deriving (Show, Eq)
d :: Integer -> Integer
d n | odd n = div (n-1) 2
| even n = error "d: aplicado sobre par"
u :: Integer -> Integer
u n | odd n = error "u: aplicado sobre impar"
| even n = 3 * (div n 2)
-- la lista guarda las claves de las operaciones que van pasando
paso :: ([Op], Integer, Integer, Integer) -> ([Op], Integer, Integer, Integer)
paso t@(_, _, _, n) | n < 7 = t
-- 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, u n) -- convierto 3*2*k en 2*3*k
| even n = paso (UTP:xs, 1, 3, (u n) + 1) -- convierto 3*2*k en 2*3*k
| odd n = paso (UTI:xs, -1, 3, (d n) + 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, 3, u n) -- convierto 3*2*k en 2*3*k
| odd n = paso (MTI:xs, 1, 3, d n) -- muevo un 3 al lado izquierdo, divido
prueba :: Integer -> [Op]
prueba x = lista where
(lista, _, _, _) = paso ([], -1, 3, 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