Skip to content

Instantly share code, notes, and snippets.

@njbartlett
Created August 4, 2010 02:39
Show Gist options
  • Save njbartlett/507550 to your computer and use it in GitHub Desktop.
Save njbartlett/507550 to your computer and use it in GitHub Desktop.
module Main where
import Control.Monad
import Data.List
type Line = [Int]
data Wire = Wire { start :: Int
, end :: Int } deriving Show
type TestCase = [Wire]
main = do
cases <- parseCases
let solns = map countCrossings cases
mapM_ printSoln $ zip [1..] solns
frame :: IO a -> IO [a]
frame p = do
count <- getLine
replicateM (read count) p
parseCases :: IO [TestCase]
parseCases = frame parseCase
parseCase :: IO TestCase
parseCase = frame getLine >>= return . linesToWires
linesToWires :: [String] -> [Wire]
linesToWires = map (\[s,e] -> Wire s e) . (map . map) read . map words
printSoln :: (Int, Int) -> IO ()
printSoln (n, count) = putStrLn $ "Case #" ++ show n ++ ": " ++ show count
countCrossings :: TestCase -> Int
countCrossings = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment