Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void countConflicts() {
- int conflicts = 0;
- Set<Integer> set = new HashSet<Integer>();
- // Row 1
- for (int i = 0; i < 4; i++) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- set = new HashSet<Integer>();
- // Row 2
- for (int i = 4; i < 8; i++) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Row 3
- set = new HashSet<Integer>();
- for (int i = 8; i < 12; i++) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Row 4
- set = new HashSet<Integer>();
- for (int i = 12; i < 16; i++) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Col 1
- set = new HashSet<Integer>();
- for (int i = 0; i < 13; i += 4) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Col 2
- set = new HashSet<Integer>();
- for (int i = 1; i < 14; i += 4) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Col 3
- set = new HashSet<Integer>();
- for (int i = 2; i < 15; i += 4) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Col 4
- set = new HashSet<Integer>();
- for (int i = 3; i < 16; i += 4) {
- if (set.contains(this.test[i])) {
- conflicts++;
- } else {
- set.add(this.test[i]);
- }
- }
- // Box top left
- set = new HashSet<Integer>();
- if (set.contains(this.test[0])) {
- conflicts++;
- } else {
- set.add(this.test[0]);
- }
- if (set.contains(this.test[1])) {
- conflicts++;
- } else {
- set.add(this.test[1]);
- }
- if (set.contains(this.test[4])) {
- conflicts++;
- } else {
- set.add(this.test[4]);
- }
- if (set.contains(this.test[5])) {
- conflicts++;
- } else {
- set.add(this.test[5]);
- }
- // Box top right
- set = new HashSet<Integer>();
- if (set.contains(this.test[2])) {
- conflicts++;
- } else {
- set.add(this.test[2]);
- }
- if (set.contains(this.test[3])) {
- conflicts++;
- } else {
- set.add(this.test[3]);
- }
- if (set.contains(this.test[6])) {
- conflicts++;
- } else {
- set.add(this.test[6]);
- }
- if (set.contains(this.test[7])) {
- conflicts++;
- } else {
- set.add(this.test[7]);
- }
- // Bx bottom left
- set = new HashSet<Integer>();
- if (set.contains(this.test[8])) {
- conflicts++;
- } else {
- set.add(this.test[8]);
- }
- if (set.contains(this.test[9])) {
- conflicts++;
- } else {
- set.add(this.test[9]);
- }
- if (set.contains(this.test[12])) {
- conflicts++;
- } else {
- set.add(this.test[12]);
- }
- if (set.contains(this.test[13])) {
- conflicts++;
- } else {
- set.add(this.test[13]);
- }
- // Box bottom right
- set = new HashSet<Integer>();
- if (set.contains(this.test[10])) {
- conflicts++;
- } else {
- set.add(this.test[10]);
- }
- if (set.contains(this.test[11])) {
- conflicts++;
- } else {
- set.add(this.test[11]);
- }
- if (set.contains(this.test[14])) {
- conflicts++;
- } else {
- set.add(this.test[14]);
- }
- if (set.contains(this.test[15])) {
- conflicts++;
- } else {
- set.add(this.test[15]);
- }
- System.out.println(conflicts);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement