[Haskell-cafe] Re: Function to detect duplicates

Jonas Almström Duregård jonas.duregard at gmail.com
Tue Feb 23 07:31:03 EST 2010


Ertugrul: while your solution is minimalistic, Rafael deemed his
~n*log n implementation too inefficient. Thus your ~n^3 implementation
is hardly an improvement...

/Jonas

On 23 February 2010 13:03, Ertugrul Soeylemez <es at ertes.de> wrote:
> Rafael Gustavo da Cunha Pereira Pinto <RafaelGCPP.Linux at gmail.com> wrote:
>
>> While solving a puzzle, I was posed the problem of finding if there
>> was no duplicates on a list.
>>
>> First I used:
>>
>> noneRepeated=null.(filter (>1)).(map length).group.sort
>>
>> But this seemed very unneficient, so I thought that I could detect the
>> duplicates while sorting, and devised this:
>>
>> import Control.Monad
>> import Data.Maybe
>>
>> noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs
>
> import Data.List
>
> noneRepeated xs = xs == nub xs
>
>
> Greets
> Ertugrul
>
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://blog.ertes.de/
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list