[Haskell-cafe] I need a hint in list processing

Luke Palmer lrpalmer at gmail.com
Mon Jun 15 04:33:48 EDT 2009


On Sun, Jun 14, 2009 at 2:06 AM, Fernan Bolando <fernanbolando at mailc.net>wrote:

> Hi all
>
> If I have a number of list
> example
> list1 = [2,3]
> list2 = [1,2]
> list3 = [2,3,4]
> list4 = [1,2,3]
>
> I want to create a list from the list above with n elements,
> non-repeating and each elements index represents 1 of the elements
> from the corresponding list so for the above input I would get.
>
> a = [3,2,4,1]
>
> ofcourse there may be several set that will satisfy the problem, so a
> list of list that satisfies would be good.


I will rephrase the problem, since some folks seem to be having a hard time
understanding it.

You want a list of four elements.  The first element comes from list1, the
second from list2, ....   And there should be no duplicates in the solution.

To start you off, here is a selection function, which computes all such
lists, but does not remove duplicates.

select :: [[a]] -> [[a]]
select [] = [[]]
select (xs:xss) = [ x:rest | y <- xs; rest <- select xss ]

Filtering out the duplicate-free lists should not be a problem.

Note: this is not an efficient solution, it is just to get you started.
Making it efficient will require understanding and modifying the above
select function, which ought to be an educational experience :-)

Luke


>
> How do I do this in haskell? or is there a code snippet that seems to
> work similarly?
>
> thanks
> fernan
>
> --
> http://www.fernski.com
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090615/3fe839d5/attachment.html


More information about the Haskell-Cafe mailing list