Created
August 4, 2010 02:39
-
-
Save njbartlett/507550 to your computer and use it in GitHub Desktop.
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
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