Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

61
LINES

< > BotCompany Repo | #1000509 // LFunctionPlusPrevious (learner)

IOIOI

1  
static class LFunctionPlusPrevious extends LearnerImpl {
2  
  static boolean debug;
3  
  Stepper stepper;
4  
  new List<O[]> examples;
5  
  
6  
  public void processInOut(O in, O out) {
7  
    examples.add(new O[] {in, out});
8  
    
9  
    if (stepper == null)
10  
      stepper = new Stepper(allFunctions(), solvedCases());
11  
12  
    while (!stepper.ended()) {
13  
      if (check(stepper.current()))
14  
        ret; // ok, keep
15  
      else
16  
        stepper.step();
17  
    }
18  
    
19  
    fail();
20  
  }
21  
22  
  boolean check(O[] fg) {
23  
    if (debug) debug("Checking " + structure(fg));
24  
    for (O[] e : examples) {
25  
      O o = tryProcess((Function) fg[0], e[0]);
26  
      if (o != null) {
27  
        O x = tryProcess(((Case) fg[1]).winner, o);
28  
        if (e[1].equals(x))
29  
          continue; // example ok
30  
      }
31  
      ret false;
32  
    }
33  
    ret true; // all examples ok
34  
  }
35  
  
36  
  public O processIn(O in) {
37  
    Object[] fg = stepper.current();
38  
    ret ((Case) fg[1]).processIn(((Function) fg[0]).process(in));
39  
  }
40  
  
41  
  static class Stepper {
42  
    List<Function> functions;
43  
    List<Case> cases;
44  
    int i1, i2;
45  
    
46  
    *(List<Function> *functions, List<Case> *cases) {}
47  
    
48  
    boolean ended() {
49  
      ret i1 >= functions.size();
50  
    }
51  
    
52  
    O[] current() {
53  
      ret new O[] {functions.get(i1), cases.get(i2)};
54  
    }
55  
    
56  
    void step() {
57  
      if (i2 < cases.size()-1) ++i2;
58  
      else { ++i1; i2 = 0; }
59  
    }
60  
  }
61  
}

download  show line numbers   

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: 532 / 921
Referenced in: [show references]