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
typealias Operator = (Int, Int) -> Int | |
fun reduce(zero: Int, vararg xs: Int): ((Operator) -> Int) { | |
var acc = zero | |
fun reductor(op: Operator): Int { | |
xs.forEach { acc = op(acc, it)} | |
return acc | |
} | |
return { reductor(it) } | |
} |
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
Django girls, Django gays | |
(E: entrevistador. A y B son los entrevistados, no consigo identificarlos por su | |
voz al 100% con los que se presentan al principio del podcast) | |
- E: Tenéis pensada alguna actividad para fomentar una sociedad “más mejor”? Es | |
una pregunta un poco rara. | |
- A: Je, ¿una sociedad más mejor? Hombre, pues mira, ahí va a haber como es la | |
<no se entiende bien> Django Girls, los Django Gays, los Django... (se oyen | |
risas) de todos los colores (más risas). Digo yo, por aquello de las cosas |
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
import Data.Number.CReal | |
nilakantha :: Int -> CReal | |
nilakantha n = 3 + (sum $ take n series) where | |
series = zipWith (\sign d -> (-1) * sign * 4 / d) (cycle [-1,1]) denominators | |
denominators = map (\x -> x * (x+1) * (x+2)) [2,4..] :: [CReal] | |
main = print $ nilakantha 150 |
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
-- http://lpaste.net/revision/5805301582249590784 | |
import Control.Arrow | |
import Data.Set as S (Set, empty, insert, member) | |
lowestFreeInt :: [Int] -> Int | |
lowestFreeInt = fst . foldl f (0, S.empty) where | |
f (n,s) x = (if (n == x) then nextFreeInt (n+1) s else n, S.insert x s) | |
lowestFreeInt' :: [Int] -> Int | |
lowestFreeInt' = fst . foldl f (0, S.empty) where |
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
-- http://lpaste.net/revision/6908970897281908736 | |
import Control.Category ((>>>)) | |
stagedComputation :: [a->a] -> a -> [a] | |
stagedComputation fs x = tail $ scanl (flip id) x fs | |
stagedComputation' :: [a->a] -> a -> [a] | |
stagedComputation' = flip $ scanl (flip id) >>> (tail .) | |
main = do |
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
-- http://lpaste.net/revision/3166527577426755584 | |
import Data.Monoid | |
replicateF :: Int -> (a -> a) -> a -> a | |
replicateF n = ((flip (!!) n . ) . iterate) | |
replicateF' :: Int -> (a -> a) -> a -> a | |
replicateF' n = appEndo . mconcat . replicate n . Endo | |
main = do |
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
-- http://lpaste.net/revision/7041447080467890176 | |
import Control.Applicative | |
braid :: [a] -> [a] -> [a] | |
braid xs ys = zip xs ys >>= (:) <$> fst <*> return . snd | |
main = do | |
print $ braid [0,2] [1,3 ..] |
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
import Control.Applicative | |
import Control.Arrow | |
foo :: (a -> b) -> [a] -> [(a,b)] | |
foo f = map ((,) <$> id <*> f) | |
foo' :: (a -> b) -> [a] -> [(a,b)] | |
foo' = map . (id &&&) | |
main = do |
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
import Data.Maybe | |
emptyIndices :: [Maybe a] -> [Int] | |
emptyIndices = map fst . filter (isNothing . snd) . zip [0..] | |
main = do | |
print $ emptyIndices [Just 1,Nothing,Just 2,Nothing,Nothing,Just 3] |
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
-- http://codepad.org/rwuXZKKQ | |
import Data.List.Split | |
squareList :: Int -> a -> [a] -> [[a]] | |
squareList n z xs = let | |
(x', xs') = splitAt n $ xs ++ repeat z | |
in take n (x' : squareList n z xs') | |
squareList' :: Int -> a -> [a] -> [[a]] | |
squareList' n z xs = take n $ chunksOf n (xs ++ repeat z) |
NewerOlder