Skip to content

Instantly share code, notes, and snippets.

mergeUniq (x : xs) (y : ys) = if x < y
then x : mergeUniq xs (y : ys)
else if y < x
then y : mergeUniq (x : xs) ys
else x : mergeUniq xs ys
mergeUniq xs [] = xs
mergeUniq [] ys = ys
mult n = map (* n) [1..]
import Random
import Graphics.Rendering.OpenGL
import Data.IORef
import Graphics.UI.GLUT
lim_stanga = -10 :: Integer
lim_dreapta = 9 :: Integer
lim_sus = 9 :: Integer
lim_jos = -9 :: Integer
module Main where
import Control.Monad
data S = C | C1 | C2 | C3 | D | O Integer deriving (Eq, Show)
data A = A | Is deriving (Eq, Show)
props = [(C3, A, O 3), (C2, A, O 2), (C1, Is, C3), (C2, Is, C3), (C, Is, C1), (C, Is, C2), (D, A, O 0)]
find f s lst = [x | x@(s', _, _) <- lst, s == s', f x] `mplus` concat [find f p lst | (s', Is, p) <- lst, s == s']
module Main where
parts n = parts' 1 n where
parts' _ 0 = [[]]
parts' p n = concatMap (\x -> (map . (:)) x $ parts' x $ n - x) [p .. n]
import Control.Monad
data T = L | B T T
instance Show T where
show L = "L"
show (B left right) = 'B' : (show left ++ show right)
newtype Parser a = Parser (String -> (a, String))
module Main (main) where
import Prelude hiding (lookup)
import Data.Map (empty, insertWith', keys, lookup, size)
import System.Random (getStdRandom, randomR)
import Control.Monad (liftM)
import System.Environment (getArgs)
parse (a : b : c : t) = insertWith' comb (a, b) ([c], 1) $ parse $ b : c : t
where comb (l, m) (r, n) = (l ++ r, m + n)
module Main where
import Data.List
data Ord a => Tree a = Node a (Tree a) (Tree a) | Leaf a
deriving (Eq)
val (Node a _ _) = a
val (Leaf a) = a
instance (Show a, Ord a) => Show (Tree a) where
module Main where
import Data.List
expand (x, y) = [(0, y), (x, 0), (v1, y), (x, v2), (x - d1, y + d1), (x + d2, y - d2)] where
d1 = min x (v2 - y)
d2 = min y (v1 - x)
v1 = 17
v2 = 13
module Main where
import Control.Monad
newtype Parser a = Parser (String -> [(a, String)])
parse (Parser p) = p
instance Monad Parser where
return r = Parser (\s -> [(r, s)])
module Main where
import Data.Map
import GHC.Handle
import GHC.IOBase
data Room = Room
{
location :: String,
description :: String,