module Main where import Data.Char import Data.List import Control.Monad import Maybe main :: IO () main = do lists <- mapM readRunFile ["times1", "times2", "times3"] print $ map (show . deviation) $ transpose lists print $ map (format . average) $ transpose lists format :: Double -> String format d = show $ (fromIntegral $ round (d * 100.0)) / 100.0 average :: [Double] -> Double average ds = sum ds / fromIntegral (length ds) deviation :: [Double] -> Double deviation ds = minimum ds / maximum ds readRunFile :: String -> IO [Double] readRunFile file = do input <- readFile file let xs = map (convert . dropWhile isSpace . drop 4) $ filter isUserLine $ lines input unless (length xs == 32) $ error "Invalid number of timings" return xs isUserLine :: String -> Bool isUserLine = (=="user") . take 4 convert :: String -> Double convert txt = read (show secs ++ "." ++ d) where secs = (60*(read m) + read s) :: Int (m, _:xs) = break (== 'm') txt (s, _:ys) = break (== '.') xs (d, _) = break (== 's') ys