forked from mcarton/Hashcode-final-round
-
Notifications
You must be signed in to change notification settings - Fork 0
/
berdes.hs
26 lines (22 loc) · 832 Bytes
/
berdes.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
import System.Environment
import Control.Monad
main :: IO ()
main = do
(fileName:_) <- getArgs
(sizes:nbrs:depart:datas) <- liftM (lines) $ readFile fileName
let [nbRow, nbCols, nbAlts] = readInts sizes
[nbCible, rayon, nbBloons, nbTurn] = readInts nbrs
[rDep, cDep] = readInts depart
cibles = map ((\[a, b] -> (a, b)) . readInts) . take nbCible $ datas
mvts = readAlts nbRow . drop nbCible $ datas
print (cibles, mvts)
return ()
readInts :: String -> [Int]
readInts = map read . words
readAlts :: Int -> [String] -> [[[(Int, Int)]]]
readAlts nbRows datas = map readAlt $ splitEvery nbRows datas
where readAlt l = map (map (\[a, b] -> (a, b)) . splitEvery 2 . readInts) $ l
splitEvery :: Int -> [a] -> [[a]]
splitEvery _ [] = []
splitEvery n l = d:splitEvery n f
where (d, f) = splitAt n l