Skip to content

Instantly share code, notes, and snippets.

@joriki
Created June 14, 2016 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joriki/1a2ae3ba07a0e316d97f31e53b7101a6 to your computer and use it in GitHub Desktop.
Save joriki/1a2ae3ba07a0e316d97f31e53b7101a6 to your computer and use it in GitHub Desktop.
Find the maximum size of an intersecting antichain on a set of n elements; see http://math.stackexchange.com/questions/1825450.
import java.util.ArrayList;
import java.util.List;
public class Question1825450 {
public static void main (String [] args) {
for (int n = 1;;n++) {
int nsubsets = 1 << n;
int max = 0;
outer:
for (long bits = 0;bits < 1L << nsubsets;bits++) {
int bitCount = 0;
for (int j = 0;j < nsubsets;j++)
if (((bits >> j) & 1) == 1)
bitCount++;
if (bitCount > max) {
List<Integer> subsets = new ArrayList<Integer> ();
for (int j = 0;j < nsubsets;j++)
if (((bits >> j) & 1) == 1)
subsets.add (j);
for (int i = 1;i < subsets.size ();i++) {
int ai = subsets.get (i);
for (int j = 0;j < i;j++) {
int aj = subsets.get (j);
if ((ai & aj) == 0 || (ai | aj) == ai || (ai | aj) == aj)
continue outer;
}
}
max = bitCount;
}
}
System.out.println (n + " : " + max);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment