static class LFunctionPlusPrevious extends LearnerImpl { static boolean debug; Stepper stepper; new List examples; public void processInOut(O in, O out) { examples.add(new O[] {in, out}); if (stepper == null) stepper = new Stepper(allFunctions(), solvedCases()); while (!stepper.ended()) { if (check(stepper.current())) ret; // ok, keep else stepper.step(); } fail(); } boolean check(O[] fg) { if (debug) debug("Checking " + structure(fg)); for (O[] e : examples) { O o = tryProcess((Function) fg[0], e[0]); if (o != null) { O x = tryProcess(((Case) fg[1]).winner, o); if (e[1].equals(x)) continue; // example ok } ret false; } ret true; // all examples ok } public O processIn(O in) { Object[] fg = stepper.current(); ret ((Case) fg[1]).processIn(((Function) fg[0]).process(in)); } static class Stepper { List functions; List cases; int i1, i2; *(List *functions, List *cases) {} boolean ended() { ret i1 >= functions.size(); } O[] current() { ret new O[] {functions.get(i1), cases.get(i2)}; } void step() { if (i2 < cases.size()-1) ++i2; else { ++i1; i2 = 0; } } } }