Skip to content

Instantly share code, notes, and snippets.

nonEmptySubsequences = foldr comb []
where comb x xs = xs ++ fmap (x:) ([]:xs)
findSum p = filter (p.sum) . nonEmptySubsequences
hasSum p = not.null . findSum p
-- Trying it in the REPL
combine :: [Either a b] -> ((a,b) -> c) -> [c]
combine xs f = combine' (Nothing, Nothing) xs
where
combine' (_, Just y) (Left l:xs) =
f (l,y) : combine' (Just l, Just y) xs
combine' (Just x, _) (Right l:xs) =
f (x,l) : combine' (Just x, Just l) xs
combine' (_, y) (Left l : xs) =
combine' (Just l, y) xs
combine' (x, _) (Right l : xs) =
module Main where
import Engine
pretty elem
= elem $= texture (fromFile "slim.jpg")
scene =
pretty cube $= rotateX 2t $= rotateY 3t
vShader :: SC.Shader GLfloat
vShader = do
pos <- attribute vec3 "position"
a_color <- attribute vec3 "a_color"
color <- varying vec3 "color"
gl_Position =: pos .: 1
color =: pos
fShader :: SC.Shader GLfloat
data Pair a = Pair a a
data Exp typ where
Vec :: Exp a -> Exp a -> Exp (Pair a)
Const :: Int -> Exp Int
-- with type
type RHS typ = String
import System.Random
import Control.Monad
count = length . filter id
avenge = do
x <- replicateM 8 randomIO
return $ count x <= 4
test n = do
import Text.Parsec
import Control.Applicative hiding ((<|>))
import qualified Data.Map as M
import Data.Either (partitionEithers)
import Data.List (intercalate)
import System.IO (hPutStrLn, stderr)
data Word = Splice String | Word String
deriving (Ord, Eq, Show)