Skip to content

Instantly share code, notes, and snippets.

@jkramer
Last active January 11, 2016 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkramer/34d955a696d6cf2f51dd to your computer and use it in GitHub Desktop.
Save jkramer/34d955a696d6cf2f51dd to your computer and use it in GitHub Desktop.
CodinGame - Temperatures
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