Last active
January 11, 2016 14:06
-
-
Save jkramer/34d955a696d6cf2f51dd to your computer and use it in GitHub Desktop.
CodinGame - Temperatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.IO | |
import Data.List | |
import Data.Ord | |
main = do | |
hSetBuffering stdout NoBuffering | |
n <- fmap read getLine | |
if n == 0 | |
then print 0 | |
else getLine >>= print . head . sortOn abs . reverse . sort . map read . words | |
-- Pasted from Data.List because it's missing in the (outdated?) version here. | |
sortOn f = map snd . sortBy (comparing fst) . map (\x -> let y = f x in y `seq` (y, x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment