[Haskell-cafe] Permutations
Jake Mcarthur
jake at pikewerks.com
Sun Nov 30 11:29:32 EST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Nov 30, 2008, at 10:17 AM, Luke Palmer wrote:
> On Sun, Nov 30, 2008 at 9:06 AM, Jake Mcarthur <jake at pikewerks.com>
> wrote:
>> Seems a bit easy, I think.
>>
>> Data.List.permutations . nub
>
> That is not what he meant. Given:
>
> [1,1,2,2]
>
> The results should be:
>
> [1,1,2,2]
> [1,2,2,1]
> [2,2,1,1]
> [1,2,1,2]
> [2,1,2,1]
> [2,1,1,2]
Heh, after a couple more seconds of thought, reversing the two
composed functions fixes it:
nub . permutations
Of course, neither my previous nonsolution nor this solution are
efficient for long lists, but I think it serves as a decent reference
implementation at least.
- - Jake
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAkkyv2wACgkQye5hVyvIUKmjBwCfSYebuPUNSqENppJG9sVxy+wB
ehYAoJjEY9M2o8ZqgN7R5pQ9x2PF54Ew
=ipuT
-----END PGP SIGNATURE-----
More information about the Haskell-Cafe
mailing list