Last active
May 27, 2018 16:14
-
-
Save th0rex/da9a8461afd6c8245d4a6cfa60e2d88c to your computer and use it in GitHub Desktop.
some haskell exercises
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
#! /usr/bin/runhaskell | |
import Control.Monad | |
import Data.List | |
mapSucc :: (a -> a -> b) -> [a] -> [b] | |
mapSucc _ [] = [] | |
mapSucc f [x] = error "can't call mapSucc with a list of only one element" | |
mapSucc f [x, y] = [f x y] | |
mapSucc f (x:y:xs) = f x y : mapSucc f (y:xs) | |
main = do | |
n <- getLine | |
xs <- replicateM (read n) getLine | |
putStrLn . show . minimum . mapSucc (flip (-)) . sort . map read $ xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment