static class LFunctionPlusPrevious extends LearnerImpl {
static boolean debug;
Stepper stepper;
new List<O[]> 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<Function> functions;
List<Case> cases;
int i1, i2;
*(List<Function> *functions, List<Case> *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; }
}
}
}Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1000509 |
| Snippet name: | LFunctionPlusPrevious (learner) |
| Eternal ID of this version: | #1000509/1 |
| Text MD5: | 19d1d6a3c694ca22cb9f7cacec33ea06 |
| Author: | stefan |
| Category: | |
| Type: | IOIOI |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2015-08-09 20:55:15 |
| Source code size: | 1420 bytes / 61 lines |
| Pitched / IR pitched: | No / Yes |
| Views / Downloads: | 749 / 971 |
| Referenced in: | #722 - IOIOI Processor (v15) #738 - IOIOI Solver (v16, most recent one) #3000382 - Answer for ferdie (>> t = 1, f = 0) #3000383 - Answer for funkoverflow (>> t=1, f=0 okay) |