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
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
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
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 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
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
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
import Ratio | |
-- función lineal; x --> (a,b) = ax + b | |
type FL = (Ratio Integer, Ratio Integer) | |
-- Composición | |
-- x --> (a, b) · (c, d) = c(ax + b) + d = (acx) + (bc + d) | |
-- (a, b) · (c, d) = (ac, bc + d) |
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
/* foldl en C con hilos */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
#include <unistd.h> | |
#include <math.h> |
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
-- Forma directa de implementar una máquina de estado vía Control.Monad.State | |
-- Implementa acciones en secuencia; no espera caso final, ejecuta k veces la máquina | |
-- Modificado a partir de http://www.haskell.org/pipermail/beginners/2008-September/000275.html | |
module FibState where | |
import Control.Monad.State | |
import Control.Monad | |
-- ¿cual es el tipo de datos del estado? |