Saturday, 7 September 2013

Lisp: How to get all possible combinations of the elements froms lists contained on a list?

Lisp: How to get all possible combinations of the elements froms lists
contained on a list?

I need to write a function in Common-Lisp that takes a list of lists and
returns a list containing all the possible combinations of the elements
from the sublists.
So, for example calling the function on a list such as ((1 2) (1 2))
should return a list like ((1 1) (1 2) (2 1) (2 2)). The input list can be
of any length and the sublists are not guaranted to have the same length.
I know how to get this with paired elements from the sublists ( inputtting
((1 2) (1 2)) returns ((1 1) (2 2)), but that's not good enough for the
arc-consistency algorithm I'm trying to write, and I'm stuck.
Thank you.

No comments:

Post a Comment