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
paso :: (Integer, Integer, Integer) -> (Integer, Integer, Integer) | |
paso (1, n, 0) = (1, n, 0) | |
-- paso (-1, 2, 1) = (1, 1, 0) | |
paso (1, 2, n) = paso (2, 3, n) -- directo (3x+1)/2 | |
paso (1, 3, n) | |
| even n = paso (1, 2, 3 * (div n 2)) -- convierto 3*2*k en 2*3*k | |
| odd n = paso (2, 3, div (n-1) 2) -- muevo un 3 al lado izquierdo, divido | |
paso (2, 3, n) | |
| even n = paso (1, 3, div n 2) -- divido | |
| odd n = paso (-1, 2, 3 * (div (n + 1) 2)) -- 3 al lado derecho, convierto |
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
data Estado = N | S | E | W deriving (Show, Eq) | |
d n = div n 2 | |
dd n = div (n-1) 2 | |
du n = div (n+1) 2 | |
paso :: (Estado, Integer) -> (Estado, Integer) | |
paso (e, 0) = (e, 0) | |
paso (N, x) | |
| even x = paso (W, 3 * (d x)) |
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
data Estado = N | S | W deriving (Show, Eq) | |
d n = div n 2 | |
dd n = div (n-1) 2 | |
du n = div (n+1) 2 | |
-- Reemplazar: no son tail recursive | |
dosportres :: Integer -> Integer | |
dosportres x = if even x then 3 * (dosportres (div x 2)) else x |
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
d n = div n 2 | |
dd n = div (n-1) 2 | |
du n = div (n+1) 2 | |
dosportres :: Integer -> Integer | |
dosportres x = (3^k) * r where | |
(k,r) = descomp x | |
-- Reemplazar: no es tail recursive | |
dptdoble :: Integer -> Integer |
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
data Op = UD | UTP | UTI | MD | MTP | MTI deriving (Show, Eq) | |
-- la lista guarda las claves de las operaciones que van pasando | |
paso :: ([Op], Integer, Integer, Integer) -> ([Op], Integer, Integer, Integer) | |
paso (l, r, n, 0) = (l, r, n, 0) | |
-- paso (1, 2, n) = paso (2, 3, n) -- directo (3x+1)/2 | |
paso (xs, 1, 2, n) = paso (UD:xs, -1, 3, n+1) -- moviendo 3 a lado derecho |
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
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) |
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
import Data.List (sortBy) | |
data Op = UP | DN deriving (Show, Eq) | |
serie :: Integer -> [Op] | |
serie 1 = cycle [UP,DN] | |
serie x | |
| odd x = UP : (serie (div ((3*x)+1) 2)) | |
| even x = DN : (serie (div x 2)) |
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
paquetes :: IO [String] | |
paquetes = readFile "packages.log" >>= (\k -> return $ lines k) >>= (\k -> return $ map (takeWhile (/= ' ')) k) | |
flechas :: IO [String] | |
flechas = readFile "portgraph.dot" >>= (\k -> return $ lines k) >>= (\k -> return $ init $ tail k) | |
-- "foo-1.2.3" -> "bar-baz-2.0.0" | |
-- se convierte en (foo, bar-baz) | |
-- se considera que no hay paquetes con subcadena "-<num>" en el nombre | |
flecha_a_par :: String -> (String, String) |
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
import subprocess as sp | |
def instalados(): | |
proceso = sp.Popen('pkg_info', stdout=sp.PIPE) | |
lineas = proceso.communicate()[0].splitlines() | |
return map (lambda k: k.split()[0], lineas) # solo la primera palabra | |
def filtra(xs): | |
return filter(lambda k: len(k) > 0 and k.find('Required') != 0 and k.find('Information') != 0 and k[0] != '\n', xs) |
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
import Data.List (sortBy) | |
data Op = UP | DN deriving (Show, Eq) | |
serie :: Integer -> [Op] | |
serie 1 = cycle [UP,DN] | |
serie x | |
| odd x = UP : (serie (div ((3*x)+1) 2)) | |
| even x = DN : (serie (div x 2)) |