Skip to content

Instantly share code, notes, and snippets.

@ilyakooo0
Last active March 24, 2017 20:04
Show Gist options
  • Save ilyakooo0/11f226140a09622dee552bb4b7f67407 to your computer and use it in GitHub Desktop.
Save ilyakooo0/11f226140a09622dee552bb4b7f67407 to your computer and use it in GitHub Desktop.
import Data.List
import Control.Monad
most :: [Int] -> Int
most ns = let
fs :: [[Int]]
fs = group . sort . map (\n -> read [head . show $ n]) $ ns
foo acc nn = case (fst acc `compare` length nn, snd acc `compare` head nn) of
(GT, _) -> (length nn, head nn)
(EQ, GT) -> (length nn, head nn)
_ -> acc
f :: [[Int]] -> (Int, Int)
f nn = foldl foo (length.head $ nn, head.head $ nn) nn
in snd $ f fs
main = do
n <- readLn
ns <- replicateM n readLn
print $ most ns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment