Created
September 25, 2012 06:24
-
-
Save joriki/3780277 to your computer and use it in GitHub Desktop.
Find the maximal size of a subset of Z_3^3 without a line; see http://math.stackexchange.com/questions/201994/center-of-mass-of-triangle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| import java.util.ArrayList; | |
| public class Question201994 { | |
| public static void main (String [] args) { | |
| List<Integer> masks = new ArrayList<Integer> (); | |
| for (int bits = 0;bits < 1 << 27;bits++) { | |
| int count = 0; | |
| int r1 = 0; | |
| int r2 = 0; | |
| int r3 = 0; | |
| for (int bit = 0;bit < 27;bit++) | |
| if ((bits & (1 << bit)) != 0) { | |
| count++; | |
| r1 += bit; | |
| r2 += bit / 3; | |
| r3 += bit / 9; | |
| } | |
| if (count == 3 && r1 % 3 == 0 && r2 % 3 == 0 && r3 % 3 == 0) | |
| masks.add (bits); | |
| } | |
| int max = 0; | |
| outer: | |
| for (int bits = 0;bits < 1 << 27;bits++) { | |
| for (int mask : masks) | |
| if ((bits & mask) == mask) | |
| continue outer; | |
| int count = 0; | |
| for (int bit = 0;bit < 27;bit++) | |
| if ((bits & (1 << bit)) != 0) | |
| count++; | |
| max = Math.max (max,count); | |
| } | |
| System.out.println ("maximal number of points without line: " + max); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment