-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRopeIntra.hs
31 lines (23 loc) · 905 Bytes
/
RopeIntra.hs
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
module Main where
import CodeJammer
import System.IO
main :: IO ()
main = do
input <- fmap (tail . lines) getContents
let cases = zipWith Case [1..] $ readCases input
let results = map codeJammer cases
mapM_ (putStrLn . show) results
readCases :: [String] -> [[String]]
readCases [] = []
readCases (x : xs) = let i = (read x) :: Int
(pre, post) = splitAt i xs
in pre : (readCases post)
codeJammer :: Case -> Result
codeJammer (Case i p) = Result i $ solve p
solve :: [String] -> String
solve input = let nums = (map ((map read) . words) input) :: [[Int]]
solve' (x:[]) = []
solve' (x:xs) = (filter (True ==) $ map (crossCheck x) xs) ++ solve' xs
in (show . length) $ solve' nums
crossCheck :: [Int] -> [Int] -> Bool
crossCheck (a1:b1:[]) (a2:b2:[]) = ((a1 - a2) * (b1 - b2)) < 0