Advertisement
Guest User

Untitled

a guest
Jul 5th, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1.  public void countConflicts() {
  2.         int conflicts = 0;
  3.         Set<Integer> set = new HashSet<Integer>();
  4.         // Row 1
  5.         for (int i = 0; i < 4; i++) {
  6.             if (set.contains(this.test[i])) {
  7.                 conflicts++;
  8.             } else {
  9.                 set.add(this.test[i]);
  10.             }
  11.         }
  12.         set = new HashSet<Integer>();
  13.         // Row 2
  14.         for (int i = 4; i < 8; i++) {
  15.             if (set.contains(this.test[i])) {
  16.                 conflicts++;
  17.             } else {
  18.                 set.add(this.test[i]);
  19.             }
  20.         }
  21.         // Row 3
  22.         set = new HashSet<Integer>();
  23.         for (int i = 8; i < 12; i++) {
  24.             if (set.contains(this.test[i])) {
  25.                 conflicts++;
  26.             } else {
  27.                 set.add(this.test[i]);
  28.             }
  29.         }
  30.         // Row 4
  31.         set = new HashSet<Integer>();
  32.         for (int i = 12; i < 16; i++) {
  33.             if (set.contains(this.test[i])) {
  34.                 conflicts++;
  35.             } else {
  36.                 set.add(this.test[i]);
  37.             }
  38.         }
  39.         // Col 1
  40.         set = new HashSet<Integer>();
  41.         for (int i = 0; i < 13; i += 4) {
  42.             if (set.contains(this.test[i])) {
  43.                 conflicts++;
  44.             } else {
  45.                 set.add(this.test[i]);
  46.             }
  47.         }
  48.         // Col 2
  49.         set = new HashSet<Integer>();
  50.         for (int i = 1; i < 14; i += 4) {
  51.             if (set.contains(this.test[i])) {
  52.                 conflicts++;
  53.             } else {
  54.                 set.add(this.test[i]);
  55.             }
  56.         }
  57.         // Col 3
  58.         set = new HashSet<Integer>();
  59.         for (int i = 2; i < 15; i += 4) {
  60.             if (set.contains(this.test[i])) {
  61.                 conflicts++;
  62.             } else {
  63.                 set.add(this.test[i]);
  64.             }
  65.         }
  66.         // Col 4
  67.         set = new HashSet<Integer>();
  68.         for (int i = 3; i < 16; i += 4) {
  69.             if (set.contains(this.test[i])) {
  70.                 conflicts++;
  71.             } else {
  72.                 set.add(this.test[i]);
  73.             }
  74.         }
  75.         // Box top left
  76.         set = new HashSet<Integer>();
  77.         if (set.contains(this.test[0])) {
  78.             conflicts++;
  79.         } else {
  80.             set.add(this.test[0]);
  81.         }
  82.         if (set.contains(this.test[1])) {
  83.             conflicts++;
  84.         } else {
  85.             set.add(this.test[1]);
  86.         }
  87.         if (set.contains(this.test[4])) {
  88.             conflicts++;
  89.         } else {
  90.             set.add(this.test[4]);
  91.         }
  92.         if (set.contains(this.test[5])) {
  93.             conflicts++;
  94.         } else {
  95.             set.add(this.test[5]);
  96.         }
  97.         // Box top right
  98.         set = new HashSet<Integer>();
  99.         if (set.contains(this.test[2])) {
  100.             conflicts++;
  101.         } else {
  102.             set.add(this.test[2]);
  103.         }
  104.         if (set.contains(this.test[3])) {
  105.             conflicts++;
  106.         } else {
  107.             set.add(this.test[3]);
  108.         }
  109.         if (set.contains(this.test[6])) {
  110.             conflicts++;
  111.         } else {
  112.             set.add(this.test[6]);
  113.         }
  114.         if (set.contains(this.test[7])) {
  115.             conflicts++;
  116.         } else {
  117.             set.add(this.test[7]);
  118.         }
  119.         // Bx bottom left
  120.         set = new HashSet<Integer>();
  121.         if (set.contains(this.test[8])) {
  122.             conflicts++;
  123.         } else {
  124.             set.add(this.test[8]);
  125.         }
  126.         if (set.contains(this.test[9])) {
  127.             conflicts++;
  128.         } else {
  129.             set.add(this.test[9]);
  130.         }
  131.         if (set.contains(this.test[12])) {
  132.             conflicts++;
  133.         } else {
  134.             set.add(this.test[12]);
  135.         }
  136.         if (set.contains(this.test[13])) {
  137.             conflicts++;
  138.         } else {
  139.             set.add(this.test[13]);
  140.         }
  141.         // Box bottom right
  142.         set = new HashSet<Integer>();
  143.         if (set.contains(this.test[10])) {
  144.             conflicts++;
  145.         } else {
  146.             set.add(this.test[10]);
  147.         }
  148.         if (set.contains(this.test[11])) {
  149.             conflicts++;
  150.         } else {
  151.             set.add(this.test[11]);
  152.         }
  153.         if (set.contains(this.test[14])) {
  154.             conflicts++;
  155.         } else {
  156.             set.add(this.test[14]);
  157.         }
  158.         if (set.contains(this.test[15])) {
  159.             conflicts++;
  160.         } else {
  161.             set.add(this.test[15]);
  162.         }
  163.  
  164.         System.out.println(conflicts);
  165.  
  166.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement