public
Last active

  • Download Gist
Ropes.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.