import Text.Printf main = interact format format = concat . zipWith fmtBlock [1..] . mkBlocks . lines nlang = length langs langs = ["Haskell", "OCaml", "C++"] langRef = 1 mkBlocks [] = [] mkBlocks xs = b : mkBlocks c where (b,c) = splitAt (2*nlang) xs fmtBlock n ls = let (ts, ss) = splitAt nlang ls ts' = map (read . (!!1) . words) ts ss' = map (map read . drop 2 . words) ss os = zipWith3 fmt langs ts' ss' tRef = ts' !! langRef [lRef, wRef] = ss' !! langRef fmt s t [l,w] = printf "%10s %8.1f %8.0f %8.0f" s (t::Double) (w::Double) (l::Double) ++ printf " %8.3f %8.3f %8.3f" (t/tRef) (w/wRef) (l/lRef) hdr = printf "%10d %8s %8s %8s %8s %8s %8s" (n::Int) "Time" "Chars" "Lines" "Rel T" "Rel C" "Rel L" in unlines $ hdr : os ++ [""]