public static Stella_Object generateCaseBasedAnswer(LogicObject probe, Surrogate slot, List cases) {
    { int num = cases.length();
      Vector slotVector = Logic.createCaseValueVector(cases, slot);
      Vector matchScores = Vector.newVector(num);
      int farthest = 0;
      Vector nearestNeighbors = Vector.newVector(Logic.$NUM_NEIGHBORS$);
      double max = 0.0;

      { int i = Stella.NULL_INTEGER;
        int iter000 = 0;
        int upperBound000 = Logic.$NUM_NEIGHBORS$ - 1;

        for (;iter000 <= upperBound000; iter000 = iter000 + 1) {
          i = iter000;
          (nearestNeighbors.theArray)[i] = (IntegerWrapper.wrapInteger(0));
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter001 = 0;
        int upperBound001 = num - 1;

        for (;iter001 <= upperBound001; iter001 = iter001 + 1) {
          i = iter001;
          (matchScores.theArray)[i] = (FloatWrapper.wrapFloat(1.0));
        }
      }
      { int i = Stella.NULL_INTEGER;
        int iter002 = 0;
        int upperBound002 = num - 1;
        Stella_Object renamed_Case = null;
        Cons iter003 = cases.theConsList;

        for (;(iter002 <= upperBound002) &&
                  (!(iter003 == Stella.NIL)); iter002 = iter002 + 1, iter003 = iter003.rest) {
          i = iter002;
          renamed_Case = iter003.value;
          if (!(probe == renamed_Case)) {
            { FloatWrapper score = LogicObject.matchInstances(probe, ((LogicObject)(renamed_Case)));

              (matchScores.theArray)[i] = score;
              if (score.wrapperValue > max) {
                max = ((double)(i));
              }
              if (score.wrapperValue > ((FloatWrapper)((matchScores.theArray)[(((IntegerWrapper)((nearestNeighbors.theArray)[farthest])).wrapperValue)])).wrapperValue) {
                (nearestNeighbors.theArray)[farthest] = (IntegerWrapper.wrapInteger(i));
                farthest = 0;
                { int j = Stella.NULL_INTEGER;
                  int iter004 = 1;
                  int upperBound003 = Logic.$NUM_NEIGHBORS$ - 1;

                  for (;iter004 <= upperBound003; iter004 = iter004 + 1) {
                    j = iter004;
                    if (((FloatWrapper)((matchScores.theArray)[(((IntegerWrapper)((nearestNeighbors.theArray)[j])).wrapperValue)])).wrapperValue < ((FloatWrapper)((matchScores.theArray)[(((IntegerWrapper)((nearestNeighbors.theArray)[farthest])).wrapperValue)])).wrapperValue) {
                      farthest = j;
                    }
                  }
                }
              }
            }
          }
        }
      }
      return (Logic.combineCaseAnswers(nearestNeighbors, matchScores, slotVector));
    }
  }