Created
October 22, 2010 03:35
-
-
Save jsoffer/639884 to your computer and use it in GitHub Desktop.
Árbol Dual
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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