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

Re: combination function help

8 views
Skip to first unread message

WJ

unread,
Sep 1, 2015, 4:33:37 PM9/1/15
to
Why this is marked as abuse? It has been marked as abuse.
Report not abuse
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)))))

Gauche Scheme:

(use srfi-42 :only (list-ec))

(define (combine lst)
(if (null? lst)
(list '())
(list-ec
(:let crest (combine (cdr lst)))
(:list item (car lst))
(:list items crest)
(cons item items))))


(combine '((1 2) (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))

--
The Authoritarian Personality extends beyond the attempt to pathologize
cohesive gentile groups to pathologizing adaptive gentile behavior in general.
The principal intellectual difficulty is that behavior that is critical to
Judaism as a successful group evolutionary strategy is conceptualized as
pathological in gentiles. --- Dr. Kevin MacDonald; "The Frankfurt School of
Social Research and the Pathologization of Gentile Group Allegiances"

WJ

unread,
Jul 8, 2016, 2:47:10 AM7/8/16
to
OCaml:

let rec combine = function
[] -> [[]]
| first::rest ->
let crest = combine rest in
List.concat
(List.map
(fun item -> List.map (fun items -> item::items) crest)
first) ;;

combine [[1;2];[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]]


--
The Haji invasion is massively subsidized by the Swedish gov't and the EU. They
will aggress against the Swedes, hassle, rape and traffic Swedish women and
they will loot Swedish property.... The police will stand down. Swedish men who
stand up to them will be punished by Swedish law....
europeancivilwar.com/sweden-to-force-resettlement-of-migrants-across-entire-country-illegal-for-municipalities-to-refuse
0 new messages