Last active
December 18, 2015 07:49
-
-
Save joseanpg/5749703 to your computer and use it in GitHub Desktop.
[Pendiente]
This file contains 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
-- Basado en | |
-- https://twitter.com/joseanpg/status/343757288089190401 | |
-- https://twitter.com/joseanpg/status/343758742455738368 | |
-- https://twitter.com/joseanpg/status/343759216424652802 | |
-- Version ultramejorable: http://t.co/da8tx1LK6r | |
-- Versión Clojure by @jneira: https://gist.github.com/jneira/5745669 | |
-- con probabilidad inversamente proporcional a las prioridades | |
import Random | |
import Control.Monad | |
getindex :: [Float] -> Float -> Int | |
getindex xs v = alpha xs (sigma * v ) 0 | |
where sigma = sum xs | |
alpha [] _ i = i | |
alpha (y:ys) a i = let a' = a - y | |
in if a' < 0 then i | |
else alpha ys a' (i+1) | |
enjoy gen xs = let zet = getindex xs | |
in gen >> randomRIO (0,1) >>= return . zet >>= print | |
main = forever (enjoy newStdGen [20,15,5]) |
This file contains 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
-- Si se impone como condición que los pesos sean naturales, no es necesario salir de la artimética Int | |
import Random | |
import Control.Monad | |
getindex :: [Int] -> Int -> Int | |
getindex xs v = alpha xs (sigma * v ) 0 | |
where sigma = sum xs | |
alpha [] _ i = i | |
alpha (y:ys) a i = let a' = a - y | |
in if a' < 0 then i | |
else alpha ys a' (i+1) | |
enjoy gen xs = let zet = getindex xs | |
in gen >> randomRIO (0,1) >>= return . zet >>= print | |
main = forever (enjoy newStdGen [20,15,5]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment