Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lib;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Test {
- public static int lim = (int) Math.pow(2, 25);
- public static int best = 0;
- public static int c(int i) {
- if(i >= 5)
- return 8-i;
- return i;
- }
- public static boolean isMine(int n, int i, int j) {
- return (n >> (c(j)*5+c(i)))%2 != 0;
- }
- public static String getBoard(int n) {
- String s = "";
- for(int j = 0; j < 9; j++) {
- for(int i = 0; i < 9; i++) {
- if(!isMine(n, i, j))
- s += ". ";
- else s+= "X ";
- }
- s += "\n";
- }
- return s;
- }
- public static int count(int n) {
- int sum = 0;
- for(int j = 0; j < 9; j++) {
- for(int i = 0; i < 9; i++) {
- if(!isMine(n, i, j)) {
- for(int b = (j==0)?0:j-1; b < (j == 8?9:j+2); b++) {
- for(int a = (i==0)?0:i-1; a < (i == 8?9:i+2); a++) {
- if(isMine(n, a, b)) {
- sum++;
- }
- }
- }
- }
- }
- }
- return sum;
- }
- public static void main(String[] args) {
- // int test = 0b10000000000000000000000000;
- // System.out.println(count(test));
- // System.out.println(getBoard(test));
- for(int i = 0; i < lim; i++) {
- // System.out.print(getBoard(i));
- // System.out.println(Integer.toBinaryString(i));
- // System.out.println();
- if(count(i) > best) {
- best = count(i);
- System.out.println(getBoard(i) + count(i) + ", " + i + ", ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement