Skip to content

Instantly share code, notes, and snippets.

View imeckler's full-sized avatar
🤷‍♂️
¯\_(ツ)_/¯

Izaak Meckler imeckler

🤷‍♂️
¯\_(ツ)_/¯
View GitHub Profile
@imeckler
imeckler / Algebra.hs
Created February 9, 2014 21:36
Algebra problems
import qualified Data.Map as M
import Data.List (nub, sort)
import qualified Data.Set as S
import Control.Applicative
-- problem 19 code
counts :: Ord a => [a] -> M.Map a Int
counts = foldl incr M.empty
where incr m x = M.insertWith (+) x 1 m
@imeckler
imeckler / RevEcho.hs
Created May 7, 2014 19:58
Pipes example
module Main where
import Pipes
import qualified Pipes.Prelude as P
import Pipes.Network.TCP
import qualified Data.ByteString as B
main :: IO ()
main =
-- "serve" is from Network.Simple.TCP
@imeckler
imeckler / Circles.elm
Created May 11, 2014 23:04
Elm example
import Keyboard
import List
import Window
import Color
import Random
input = dropRepeats Keyboard.space
ticks = fps 30
(declare-datatypes () (
(Ty (base (idx Int))
(arrow (src Ty) (tar Ty))
(prod (c1 Ty) (c2 Ty))
)))
(declare-datatypes () (
(Expr exprA
exprAtoBtoC
exprB
diag = go [] where
go active (xs:xss) = map head active ++ go (xs:map tail active) xss
@imeckler
imeckler / gist:3401817
Created August 20, 2012 07:22
All strings
-- The list where nth element is the list of strings of length n.
strings = iterate (map (:) letters <*>) letterStrings
where letterStrings = map (:[]) letters
letters = ['a'..'z']
@imeckler
imeckler / gist:3763245
Created September 21, 2012 19:00
LiveScript Guard
guard(pred, f) = if pred then f!
g(x) ->
y = getY!
<~ guard (x != y)
x + y
@imeckler
imeckler / Wordcount.hs
Last active October 12, 2015 19:18
A wordcount program in Haskell as an example of programming as data transformation
import qualified Data.Map as M
import Control.Arrow ((>>>))
import Data.List (intercalate)
import GHC.Exts (sortWith)
main = interact $ words
>>> foldr incr M.empty
>>> M.toList
>>> sortWith (negate . snd)
>>> map show
@imeckler
imeckler / parse.hs
Created December 7, 2012 20:47
Booth_parse
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
import System.Directory (getDirectoryContents)
import qualified System.IO.Strict as S
import Data.String.Utils (split, join)
import qualified Data.HashMap.Lazy as M
import qualified Data.HashSet as H
import qualified Data.ByteString.Lazy as B
@imeckler
imeckler / Random_walk.hs
Last active December 13, 2015 18:58
A fast Haskell program to help answer the following question: How long does it take a person randomly walking on a grid to touch every square?
import Prelude hiding (scanl, length, takeWhile, sum, map)
import Data.List.Stream
import System.Random.Mersenne.Pure64
import qualified Data.Set as S
import Data.Word
randUpTo :: Int -> PureMT -> [Int]
randUpTo n gen = unfoldr make gen
where make g = let (k, g') = randomInt g in Just (k `mod` n, g')