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

55
LINES

< > BotCompany Repo | #1004688 // Predict (dev.)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (2241L/15K/50K).

1  
!752
2  
3  
p {
4  
  S text = loadSnippet("#1004687");
5  
  InfiniteStream stream1 = new InfiniteStream(text + "\n***\n");
6  
  O stream2 = predictor();
7  
  int n = 0, score = 0;
8  
  double theScore = 0;
9  
  while licensed {
10  
    char c = stream1.next();
11  
    Character d = cast call(stream2, "predict");
12  
    if (eq(c, d))
13  
      ++score;
14  
    ++n;
15  
    call(stream2, "feed", c);
16  
    
17  
    if (stream1.atStart()) {
18  
      theScore = ((double) score)/n*100;
19  
      print("score: " + formatDouble(theScore, 2));
20  
      score = n = 0;
21  
    }
22  
  }
23  
}
24  
25  
static O predictor() {
26  
  ret new O {
27  
    char c = '!';
28  
    Character predict() { ret c; }
29  
    void feed(char c) { this.c = c; }
30  
  };
31  
  
32  
  /*ret new O {
33  
    Character predict() { ret null; }
34  
    void feed(char c) {}
35  
  };*/
36  
}
37  
38  
sclass InfiniteStream {
39  
  S text;
40  
  int pos;
41  
  
42  
  *(S *text) {
43  
    assertNempty(text);
44  
  }
45  
  
46  
  char next() {
47  
    char c = text.charAt(pos);
48  
    pos = (pos+1) % l(text);
49  
    ret c;
50  
  }
51  
  
52  
  bool atStart() {
53  
    ret pos == 0;
54  
  }
55  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1004688
Snippet name: Predict (dev.)
Eternal ID of this version: #1004688/1
Text MD5: 8ee589bc76a736f3e1388dd95b70718f
Transpilation MD5: 8b44455bff32bb8725ee88e87dd5c7cb
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-08-26 23:09:06
Source code size: 1024 bytes / 55 lines
Pitched / IR pitched: No / No
Views / Downloads: 494 / 550
Referenced in: [show references]