This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main :: IO () | |
main = scotty 3000 app | |
app :: ScottyM () | |
app = do | |
get "/favicon.ico" $ html "ಠ_ಠ" | |
get "/:method" $ do | |
r <- request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 |