Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created October 22, 2010 03:35
Show Gist options
  • Save jsoffer/639884 to your computer and use it in GitHub Desktop.
Save jsoffer/639884 to your computer and use it in GitHub Desktop.
Árbol Dual
type BiNodo = (Int,[(Integer,(Int,Integer))])
nivelArbolBiLista :: BiNodo -> BiNodo
nivelArbolBiLista (k,xs) = (k+1,concatMap g xs) where
d = 2^k
g (x,(n,y)) = [izq,der] where
izq = (ii,(n,di))
der = (id,(n+1,dd))
(ii,id) = if even y then (x,x+d) else (x+d,x)
di = if even y
then quot y 2
else quot (y + 3^n) 2
dd = if odd y
then quot (3*y + 1) 2
else quot (3*y + 3^(n+1) + 1) 2
nivel n = secuencia !! n where
secuencia = map (\ (_,xs) -> map (\ (a,(b,c)) -> (a,c)) xs) sec
sec = iterate nivelArbolBiLista (2,[(3,(2,8))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment