Skip to content

Instantly share code, notes, and snippets.

@th0rex
Last active May 27, 2018 16:14
Show Gist options
  • Save th0rex/da9a8461afd6c8245d4a6cfa60e2d88c to your computer and use it in GitHub Desktop.
Save th0rex/da9a8461afd6c8245d4a6cfa60e2d88c to your computer and use it in GitHub Desktop.
some haskell exercises
#! /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