Skip to content

Instantly share code, notes, and snippets.

@jsoffer
Created October 8, 2010 15:12
Show Gist options
  • Save jsoffer/616940 to your computer and use it in GitHub Desktop.
Save jsoffer/616940 to your computer and use it in GitHub Desktop.
type Nodo = ((Int,Integer),(Int,Integer))
nivelGiros :: [(Int,Integer)] -> [(Int,Integer)]
nivelGiros xs = concatMap g xs where
g :: (Int,Integer) -> [(Int,Integer)]
g (n,x) = [(n,izq),(n+1,der)] where
izq = if even x then par else rimpar
der = if even x then rpar else impar
par = quot x 2
impar = quot (3*x + 1) 2
rpar = quot (3*x + 3^(n+1) + 1) 2
rimpar = quot (x + 3^n) 2
--
nivelArbolBilista :: [Nodo] -> [Nodo]
nivelArbolBilista xs = concatMap g xs where
g :: Nodo -> [Nodo]
g (a@(ni,xi),b@(nd,xd)) = [izq,der] where
izq = ((ni,fizq b),(nd,fizq a))
der = ((ni+1, fder b),(nd+1,fder a))
fizq (n,x) = if even x then quot x 2 else quot (x + 3^n) 2
fder (n,x) = if odd x
then quot (3*x + 1) 2
else quot (3*x + 3^(n+1) + 1) 2
{-
let z = zip (giros !! 6) (giros !! 7)
let bilista = iterate nivelArbolBilista [((2,2),(2,8))]
mapM_ print $ take 40 $ tail $ map (z !!) [0..]
mapM_ print $ take 40 $ concatMap (bilista !!) [0..]
-}
listas :: (String,String)
listas = ('0':pares,'1':impares) where
g (_,x) = if odd x then '1' else '0'
pares = map g p
impares = map g i
(p,i) = unzip $ concat $ iterate nivelArbolBilista [((2,2),(2,8))]
--
construye n = map ((\k->if k then '1' else '0').odd.snd) $
(iterate nivelGiros [(1,2)]) !! n
pares' = construye 16
impares' = construye 17
testpares = all id $ zipWith (==) pares' (fst listas)
testimpares = all id $ zipWith (==) impares' (snd listas)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment