code: public static void getGenotype(int index, Integer alleles[]) {
  //        index++;
  //        double value = (-3 + Math.sqrt(1 + 8 * index)) / 2;    // slower than the iterating version, right?
  //        alleles[1] = new Double(Math.ceil(value)).intValue();
  //        alleles[0] = alleles[1] - ((alleles[1] + 1) * (alleles[1] +2) / 2 - index);
  
          int cursor = 0;
          final int MAX_ALLOWED_ALLELES = 100;   // should we allow more than 100 alleles?
          for (int i = 0; i < MAX_ALLOWED_ALLELES; i++) {
              for (int j = 0; j <= i; j++) {
                  if (cursor == index) {
                      alleles[0] = j;
                      alleles[1] = i;
                      return;
                  }
                  cursor++;
              }
          }
      }
docs: returns in alleles[] the genotype specified in index in the sequence:
  0/0, 0/1, 1/1, 0/2, 1/2, 2/2, 0/3...
  @param index in this sequence, starting in 0
  @param alleles returned genotype.