import Text.Printf main = interact format table = False format = concat . zipWith (fmtBlock table) [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 tbl n ls = let (trs, tre, tds, tde, ths, the, tables, tablee) = if tbl then ("", "", "", "", "", "", "", "

") else ("", "", "", "", "", "", "", "") (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 "%s%s%-10s%s %s%8.1f%s %s%8.0f%s %s%8.0f%s" trs tds s tde tds (t::Double) tde tds (w::Double) tde tds (l::Double) tde ++ printf " %s%8.3f%s %s%8.3f%s %s%8.3f%s%s" tds (t/tRef) tde tds (w/wRef) tde tds (l/lRef) tde tre hdr = printf "%s%sray%-7d%s %s%8s%s %s%8s%s %s%8s%s %s%8s%s %s%8s%s %s%8s%s%s" trs ths (n::Int) the tds "Time" tde tds "Chars" tde tds "Lines" tde tds "Rel T" tde tds "Rel C" tde tds "Rel L" tde tre in unlines $ tables : hdr : os ++ [tablee]