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/QomzEZSD | |
import System.Random | |
import Control.Arrow | |
addNoise :: (Num a, Random a) => a -> [a] -> StdGen -> ([a], StdGen) | |
addNoise x l gen = let | |
range = ((id &&& negate) . abs) x | |
noised = zipWith (+) l (randomRs range gen) | |
in (noised, fst $ split gen) |
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/QollsjCw | |
import Control.Monad | |
import Data.Function | |
import Data.List | |
import Test.QuickCheck | |
-- $setup | |
-- >>> import Control.Applicative ((<*>)) | |
-- >>> import Data.List (isInfixOf) | |
-- >>> import Test.QuickCheck |
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/JkbvjiK3 | |
import Test.QuickCheck | |
-- $setup | |
-- >>> import Data.Maybe | |
-- >>> let backPartner = (>>= partner) . (>>= partner) | |
data Person a = Single a | Married a (Person a) deriving Show | |
partner :: Person a -> Maybe (Person a) | |
partner (Married _ p) = Just p |
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/4ZT5ZCwH | |
import Control.Applicative | |
import Control.Arrow | |
import Data.List | |
maximumList :: Ord a => [a] -> [a] | |
maximumList = mapAccumL (\x -> max x &&& max x) <$> head <*> id >>> snd | |
-- Different approach | |
maximumList' :: Ord a => [a] -> [a] |
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
-- See http://codepad.org/gXEcCgBI | |
import Control.Applicative | |
pairToList :: (a,a) -> [a] | |
pairToList = (:) <$> fst <*> replicate 1 . snd | |
main = print $ pairToList (1,2) |
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
#define is_C 1 | |
#ifndef is_C | |
#>++++[<+++++++++++++++++++++++++>-]<[>>[-]>++++[<++++++++++++++++++>-] | |
#<.>+++++[<++++++++>-]<-.---.-----------.[-]>++++[<++++++++>-]<.>+++++++ | |
#[<+++++++++++>-]<.++++++++.-------.----------.+++++++++++.[-]++++++++++.<<-] | |
#[-][ | |
def principal(): | |
return | |
def semicolon(): | |
return |
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
In [1]: class A(object): | |
...: x = [1,2,3] | |
...: | |
In [2]: class B(A): pass | |
...: | |
In [3]: b = B() | |
In [4]: b.x.append(33) |
NewerOlder