[ create a new paste ] login | about

Link: http://codepad.org/9n8za2lD    [ raw code | output | fork ]

johannes - Haskell, pasted on Nov 9:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Main where

import Data.List

-- | Minimally exclusive member of a set (i.e., list)
mex :: [Int] -> Int 
mex xs = f (sort $ nub xs) 0
  where f [] a = a
        f (x:xs) a | x > a     = f xs a
                   | otherwise = f xs $ succ a

main :: IO ()
main = do
    print $ mex [0, 1, 1, 1]


Output:
1
2


Create a new paste based on this one


Comments: