Skip to content

Instantly share code, notes, and snippets.

View svdberg's full-sized avatar

Sander van den Berg svdberg

View GitHub Profile
(ns googlecodejam
[:use clojure.string])
(def example-input ["ejp mysljylc kd kxveddknmc re jsicpdrysi"
"rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"
"de kr kd eoya kw aej tysr re ujdr lkgc jv"])
(def google ["our language is impossible to understand"
"there are twenty six factorial possibilities"
"so it is okay if you want to just give up"])
import Data.List
import Data.Char
import Data.List.HT
type Password = String
type Cipher = [String]
--this should take 5 letters at a time, removing earlier seen letters
--also we should add the remaining letters of the alphabet
createCipherSquare :: Password -> Cipher
import Data.List
import Data.List.Split
import Data.Char
import qualified Data.Map as Map
import Data.List.HT
type Password = String
type Direction = Int
--new implementation: change Cipher to Map
import Data.List.Split
import qualified Data.Map as Map
import Data.List.HT
buildCipher pw = Map.fromList $ zip [ (x,y) | x <- [0..4], y <- [0..4] ] (concat $ build pw)
where
build = chunk 5 . (`union` delete 'J' ['A'..'Z']) . nub . process --calculate the list of characters in the right order
process = replace "J" "I" . map toUpper . filter isLetter
@svdberg
svdberg / 3nightclubs.scala
Created June 23, 2012 07:12 — forked from oxbowlakes/3nightclubs.scala
A Tale of 3 Nightclubs
/**
* Part Zero : 10:15 Saturday Night
*
* (In which we will see how to let the type system help you handle failure)...
*
* First let's define a domain. (All the following requires scala 2.9.x and scalaz 6.0)
*/
import scalaz._
import Scalaz._
@svdberg
svdberg / main.hs
Created June 26, 2012 13:49
Implementation of REST GET of feedings.
{-# LANGUAGE OverloadedStrings, ExtendedDefaultRules, NoMonomorphismRestriction #-}
import Database.MongoDB as M
import Control.Monad.Trans (liftIO)
import System.Locale
import Data.Time
import Data.Time.Format
import Data.Bson.Json
import Data.Aeson.Encode
import Data.Aeson
-- | ToJSON and FromJSON instances for BSON Documents and Values
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, OverloadedStrings #-}
module Data.Bson.Json where
import qualified Data.Bson as B
import qualified Data.Aeson as J
import qualified Data.Attoparsec.Number as J (Number(..))
import qualified Data.Vector as V
main :: IO ()
main = scotty 3000 app
app :: ScottyM ()
app = do
get "/favicon.ico" $ html "ಠ_ಠ"
get "/:method" $ do
r <- request
{-# LANGUAGE TupleSections, OverloadedStrings #-}
module Handler.Feeding where
import Import
import Network.HTTP.Types (status201, status204, status200)
{- This module contains the Feeding resource -}
getFeedingR :: FeedingId -> Handler RepJson
getFeedingR fid = runDB (get404 fid) >>= jsonToRepJson . Entity fid
{-# LANGUAGE TupleSections, OverloadedStrings #-}
module Handler.Feeding where
import Import
import Network.HTTP.Types (status201, status204, status200)
import Data.Maybe
{- This module contains the Feeding resource -}
getFeedingR :: FeedingId -> Handler RepJson