Created
October 26, 2010 22:21
-
-
Save jsoffer/647962 to your computer and use it in GitHub Desktop.
Árbol binario Collatz extendido
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
----------------- por estilo --------------------- | |
import Prelude hiding ((/)) | |
infixl 7 / | |
(/) = quot | |
par = even | |
impar = odd | |
-------------------------------------------------- | |
type Nodo = (Int,Int,Integer,Integer) | |
-- hijo izquierdo de un nodo | |
hi :: Nodo -> Nodo | |
hi (n,k,i,d) | |
| par d = (n, k+1, i, d/2) | |
| impar d = (n, k+1, i + 2^k, (d + 3^n)/2) | |
-- hijo derecho | |
hd :: Nodo -> Nodo | |
hd (n,k,i,d) | |
| par d = (n+1, k+1, i + 2^k, (3*(d + 3^n) + 1)/2) | |
| impar d = (n+1, k+1, i, (3*d + 1)/2) | |
------------------------- construcciones ------------------ | |
type Nivel = [Nodo] | |
nivel' :: Nivel -> Nivel | |
nivel' = concatMap (\k -> [hi k, hd k]) | |
niveles :: [Nivel] | |
niveles = iterate nivel' [(0,0,0,0)] | |
nivel :: Int -> Nivel | |
nivel = (niveles !!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment