Project

General

Profile

combos.java

Greg Shah, 10/27/2015 04:34 PM

Download (1.85 KB)

 
1
import java.util.*;
2

    
3
public class combos
4
{
5
   private static final int[] vals = new int[] { 0, 31, 32, 63, 64, 95, 96, 127, 128, 159, 160, 191, 192, 223, 224, 255 };
6
   
7
   private static Tuple[] variants(int[] vals)
8
   {
9
      ArrayList<Tuple> list = new ArrayList<Tuple>();
10
      
11
      for (int i = 0; i < vals.length; i++)
12
      {
13
         for (int j = 0; j < vals.length; j++)
14
         {
15
            list.add(new Tuple(vals[i], vals[j]));
16
         }
17
      }
18
      
19
      int r = 3 - (list.size() % 3);
20
      
21
      // return an array that is (size % 3) == 0
22
      for (int k = 0; k < r; k++)
23
      {
24
         list.add(new Tuple(0, 0));
25
      }
26
      
27
      return list.toArray(new Tuple[0]);
28
   }
29
   
30
   public static void main(String[] args)
31
   {
32
      Tuple[] tuples = variants(vals);
33
      
34
      ArrayList<TestValue> tests = new ArrayList<TestValue>();
35
      
36
      int i = 0;
37
      
38
      while (i < tuples.length)
39
      {
40
         tests.add(new TestValue(tuples[i++], tuples[i++], tuples[i++]));
41
      }
42
      
43
      System.out.printf("Total = %d\n", tests.size());
44
      
45
      for (TestValue tv : tests)
46
      {
47
         System.out.println(tv.toString());
48
      }
49
   }
50
   
51
   private static class Tuple
52
   {
53
      int fg;
54
      int bg;
55
      
56
      public Tuple(int fg, int bg)
57
      {
58
         this.fg = fg;
59
         this.bg = bg;
60
      }
61
   }
62
   
63
   private static class TestValue
64
   {
65
      int fgR;
66
      int fgG;
67
      int fgB;
68
      int bgR;
69
      int bgG;
70
      int bgB;
71
      
72
      TestValue(Tuple red, Tuple green, Tuple blue)
73
      {
74
         this.fgR = red.fg;
75
         this.bgR = red.bg;
76
         this.fgG = green.fg;
77
         this.bgG = green.bg;
78
         this.fgB = blue.fg;
79
         this.bgB = blue.bg;
80
      }
81
      
82
      public String toString()
83
      {
84
         return String.format("fg (%d, %d, %d) + bg (%d, %d, %d)", fgR, fgG, fgB, bgR, bgG, bgB);
85
      }
86
   }
87
}