import System.IO import Data.Char import Data.Array import Data.List main = do h <- openFile "girls2005.txt" ReadMode c <- hGetContents h let xs = map putStrLn . map show . reverse . sort . map Cell . assocs $ f 1 2 (lines c) sequence_ xs putStrLn "Finished" newtype Cell = Cell ((Char,Char),Int) deriving Eq instance Ord Cell where Cell (_,i) <= Cell (_,j) = i <= j instance Show Cell where show (Cell ((i,j),f)) = i : ',' : j : ',' : show f hit m n l = (toUpper (l!!(m-1)), toUpper (l!!(n-1))) f m n c = accumArray (+) 0 (('A','A'),('Z','Z')) [(hit m n l,1) | l <- c]