No title

Anonymous Coward 2018-03-08 21:30:31.521076 UTC

1import Control.Monad
2import Data.List
3
4maxPi = 10000000
5
6readLines :: IO [Int]
7readLines = do
8 nLines <- getLine
9 inputs <- replicateM (read nLines) (fmap read getLine :: IO Int)
10 return inputs
11
12findClosest' :: (Integral a) => [a] -> a -> a
13findClosest' [] a = a
14findClosest' (x:s) a = findClosest' s (max a x)
15
16findClosest :: [Int] -> Int
17findClosest [] = maxPi
18findClosest a = findClosest' (sort a) maxPi
19
20main :: IO ()
21main = do
22 let input = readLines
23 let result = findClosest input
24 putStrLn (show result)
25