Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

:Re: combination function help

4 views
Skip to first unread message

Robert L.

unread,
Nov 30, 2016, 4:17:16 PM11/30/16
to
Tron3k wrote:

> > i am looking for a function that does the following combination 'across
> > lists'.
> >
> > ((1 2) (3 4) (5 6))
> >
> > to
> >
> > ((1 3 5) (2 3 5) ( 1 4 5) ( 2 4 5) ( 1 3 6) ( 2 3 6) ( 1 4 6) ( 2 4 6))
> >
> > thanks,
> > -AC
>
> Here's my try at this function:
>
> (defun combine (lst)
> (if (endp lst)
> (list '())
> (loop with crest = (combine (rest lst))
> for item in (first lst)
> nconc (loop for items in crest
> collect (cons item items)))))

MatzLisp (Ruby):

[1,2].product( [3,4], [5,6])

===>

[[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6],
[2, 4, 5], [2, 4, 6]]


--
[H]e was prosecuted ... for "denying" the gas chambers and the six million
figure.... [A] Swiss court sentenced him to 15 months imprisonment.... Rather
than serve the sentence, ... Graf went into exile. In 2001 he married a
Russian historian in Moscow. www.revisionists.com/revisionists/graf.html
0 new messages