| Bytes | Lang | Time | Link |
|---|---|---|---|
| 307 | Python3 | 250909T181748Z | Ajax1234 |
| nan | CJam | 150104T153022Z | jimmy230 |
| nan | Mathematica | 150616T065428Z | alephalp |
| 2004 | Java 2014 10 = | 150104T203838Z | PoweredB |
Python3, 307 bytes
def f(p,q):
S={j for k in p+q for j in k}
g,C=[(a,b)for a in S for b in S if any(not{a,b}-{*j}for j in p+q)if a<b],[]
while g:
n,*g=g
Q,s=[n],[n]
for I in Q:t=[i for i in g if{*i}&{*I}];s+=t;Q+=t;g={*g}-{*t}
C+=[{j for k in s for j in k}]
return C or p,[K for a in p for b in q if(K:={*a}&{*b})]
CJam, 32 - 10 = 22
q_~{_{T&},:U-U:+a+}fTp~m*::&La-p
::& is newer than this question.
CJam, 36 - 10 = 26
q_~{:T;_{T&},:U-U:+a+}/p~m*{~&}%La-p
Input:
[[0] [1] [2 3 4 7 6]]
[[2 3] [4 7] [6] [1 0]]
Output:
[[2 3 4 7 6] [0 1]]
[[0] [1] [2 3] [4 7] [6]]
Explanation
q " Read the input. ";
_~ " Evaluate a copy. ";
{:T; " For each list T in the second partition: ";
_{T&}, " Select all lists in the first partition which share items with T. ";
:U- " Save to U and remove them from the first partition. ";
U:+a+ " Append the union of U to the first partition. ";
}/
p " Print the meet. ";
~ " Evaluate another copy. ";
m* " Get the Cartesian product. ";
{~&}% " Get the intersections of each pair of lists. ";
La- " Remove empty lists. ";
p " Print. ";
Mathematica, 127 - 10 = 117
Not fully golfed.
{ConnectedComponents@Graph@Union@##,FindClique[Graph@Intersection@##,Infinity,All]}&@@(Union@@(Rule@@@Tuples[#,2]&/@#)&/@{##})&
Java: 2014 (-10) = 2004 bytes
import java.util.*;public class A{static List<List<Set<Integer>>>b(Integer[][]c,Integer[][]d){Integer[][]e;Integer[][]f;if(c.length<=d.length){e=c;f=d;}else{e=d;f=c;}
Q g=h(e);List<List<Set<Integer>>>i=new ArrayList<>();i.add(j(f,g));i.add(k(f,g));System.out.println(i.toString());return i;}
static List<Set<Integer>>j(Integer[][]l,Q m){for(Integer[]o:l){if(o.length>1){n(m,o);}}
return p(m);}
static List<Set<Integer>>k(Integer[][]q,Q r){List<Set<Integer>>s=new ArrayList<>();for(Integer[]t:q){for(Set<Integer>u:v(r,t).values()){s.add(u);}}
return s;}
static Map<R,Set<Integer>>v(Q w,Integer[]x){Map<R,Set<Integer>>y=new HashMap<>();for(Integer z:x){R a=w.getSubset(z);if(!y.containsKey(a)){y.put(a,new HashSet<>());}
y.get(a).add(z);}
return y;}
static List<Set<Integer>>p(Q partition){partition.b();List<Set<Integer>>c=new ArrayList<>();for(R d:partition.y){Set<Integer>e=new HashSet<>();R f=d;while(f!=null&&!f.g){e.addAll(f.t);f.g=true;f=f.s;}
if(!e.isEmpty()){c.add(e);}}
return c;}
static void n(Q h,Integer[]i){for(int j:i){R k=h.getSubset(j);for(int l:i){R m=h.getSubset(l);if(k.s==null&&k!=m&&k!=m.s){k.s=m;}}}}
static Q h(Integer[][]n){List<R>o=new ArrayList<>();for(Integer[]p:n){o.add(new R(p));}
return new Q(o);}}
class R{R s;Set<Integer>t;boolean g=false;R(Integer[]u){this.t=Collections.unmodifiableSet(new HashSet<>(Arrays.asList(u)));}
R(Set<Integer>v){this.t=Collections.unmodifiableSet(v);}@Override
public int hashCode(){final int p=31;int r=1;r=p*r+((t==null)?0:t.hashCode());return r;}@Override
public boolean equals(Object x){if(this==x)
return true;if(x==null)
return false;if(getClass()!=x.getClass())
return false;R other=(R)x;if(t==null){if(other.t!=null)
return false;}else if(!t.equals(other.t))
return false;return true;}}
class Q{List<R>y;R getSubset(Integer z){for(R a:y){if(a.t.contains(z)){return a;}}
return null;}
Q(List<R>b){this.y=b;}
void b(){List<R>c=new ArrayList<>();for(int i=0;i<y.size();i++){if(y.get(i).s!=null){c.add(y.get(i));y.remove(i);}}
c.addAll(y);this.y=c;}}
Run by calling the b() function with two Integer[][].
Using the given inputs, outputs are:
[[[1]], [[1]]]
[[[0, 1, 2, 3]], [[0, 1], [2], [3]]]
[[[0, 1], [2, 3, 4, 6, 7]], [[2, 3], [4, 7], [6], [1], [0]]]
[[[0, 1, 2, 3, 4, 5, 6]], [[3], [0], [6], [4], [2], [5], [1]]]