Skip to main content
added 46 characters in body
Source Link
skyfire
  • 487
  • 2
  • 7

Here is the naive way (hoping for a more idiomatic, functional soln from someone).

p1 = {{1, 2, 6}, {1, 2, 4, 6}, {1, 2, 3, 5, 6}}; p2 = {{3, 5, 6}}; list = {} Do[ AppendTo[list, {}] Do[     If[IntersectingQ[p1[[x]], p2[[y]]],   Intersection[p1[[x]], p2[[y]]] // AppendTo[listAppendTo[list[[y]], #] &,  Nothing]    , {x, 1, Length[p1]}] , {y, 1, Length[p2]}] list ``` 

Here is the naive way (hoping for a more idiomatic, functional soln from someone).

p1 = {{1, 2, 6}, {1, 2, 4, 6}, {1, 2, 3, 5, 6}}; p2 = {{3, 5, 6}}; list = {} Do[ Do[ If[IntersectingQ[p1[[x]], p2[[y]]], Intersection[p1[[x]], p2[[y]]] // AppendTo[list, #] &, Nothing] , {x, 1, Length[p1]}] , {y, 1, Length[p2]}] list 

Here is the naive way (hoping for a more idiomatic, functional soln from someone).

p1 = {{1, 2, 6}, {1, 2, 4, 6}, {1, 2, 3, 5, 6}}; p2 = {{3, 5, 6}}; list = {} Do[ AppendTo[list, {}] Do[     If[IntersectingQ[p1[[x]], p2[[y]]],   Intersection[p1[[x]], p2[[y]]] // AppendTo[list[[y]], #] &,  Nothing]    , {x, 1, Length[p1]}] , {y, 1, Length[p2]}] list ``` 
Source Link
skyfire
  • 487
  • 2
  • 7

Here is the naive way (hoping for a more idiomatic, functional soln from someone).

p1 = {{1, 2, 6}, {1, 2, 4, 6}, {1, 2, 3, 5, 6}}; p2 = {{3, 5, 6}}; list = {} Do[ Do[ If[IntersectingQ[p1[[x]], p2[[y]]], Intersection[p1[[x]], p2[[y]]] // AppendTo[list, #] &, Nothing] , {x, 1, Length[p1]}] , {y, 1, Length[p2]}] list