Instantly share code, notes, and snippets.

View gist:510622
In http://github.com/johanlindberg/langgeeks/commit/3e6249fcd36be6685cce2a6936da8dd2471cbd51
you have:
> process :: String -> (Char, [String])
> process filename = do contents <- readFile filename
> return (getPlayer contents, getBoard contents)
It looks like you want to read the file and extract the player and board to pass this on to
another function. All that is missing here is the IO in the type signature.
View GuessGame-abstracted.hs
module Main where
import System.Random
import Data.Function
processGuess :: Int -> IO () -> IO ()
processGuess answer cont = do
n <- getLine
case compare (read n) answer of
EQ -> putStrLn "Awesome!!!!"
View Rope Intranet benchmark
-- | This program benchmarks different versions of the counting function for
-- the Rope Intranet problem for Google Code Jam
-- http://code.google.com/codejam/contest/dashboard?c=619102#.
--
-- To compile:
-- >>> ghc -O2 --make bench.hs
--
-- To run (Windows):
-- >>> Bench
View guessMaker.hs
module Main where
makeAGuess :: Int -> Int -> Int
makeAGuess i j = (i + j) `div` 2
guess :: Int -> Int -> IO ()
guess i j = do
let x = makeAGuess i j
putStrLn (show x)
View guesser.hs
module Main where
import Data.Char
import Data.List
data Guess
= Guess Int Guess Guess
| GiveUp
| Done
View expressions.hs
module Expressions where
import Data.Maybe
import Text.Printf
import Control.Applicative
data Expr = Term Int | Op Operator Expr Expr | Var String
deriving (Show, Eq)
data Operator = Sum | Mult | Sub | Div
View gist:702671
import Data.Maybe
import Text.Printf
import Data.Char
import Control.Monad
data Expr = Term Int | Op Operator Expr Expr | Var String
deriving (Show, Eq)
data Operator = Sum | Mult | Sub | Div
deriving (Show, Eq)
View gist:736615
module Main where
import Control.Arrow
import Data.Array
import Data.Char
import Data.Bits
import Data.Function
import Data.List
import Data.Maybe
type Bark = Array (Int, Int) Bool
View gist:782199
module Main where
import Text.Printf
profit :: Integer -> Integer -> [Integer] -> Integer
profit cap rides groups
| sum groups <= cap = rides * sum groups
| otherwise = profit' cap rides (cycle groups)
where
View gist:791274
-- This program solves the Theme Park Google CodeJam problem at
-- http://code.google.com/codejam/contest/dashboard?c=433101#s=p2
--
-- I've tried to make the code clear whilst employing a selection of Haskell library
-- functions and idioms. I've also gone for efficiency, probably over optimizing in
-- places in order to demonstrate some techniques.
module Main where
import Data.List