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).

!752

p {
  S text = loadSnippet("#1004687");
  InfiniteStream stream1 = new InfiniteStream(text + "\n***\n");
  O stream2 = predictor();
  int n = 0, score = 0;
  double theScore = 0;
  while licensed {
    char c = stream1.next();
    Character d = cast call(stream2, "predict");
    if (eq(c, d))
      ++score;
    ++n;
    call(stream2, "feed", c);
    
    if (stream1.atStart()) {
      theScore = ((double) score)/n*100;
      print("score: " + formatDouble(theScore, 2));
      score = n = 0;
    }
  }
}

static O predictor() {
  ret new O {
    char c = '!';
    Character predict() { ret c; }
    void feed(char c) { this.c = c; }
  };
  
  /*ret new O {
    Character predict() { ret null; }
    void feed(char c) {}
  };*/
}

sclass InfiniteStream {
  S text;
  int pos;
  
  *(S *text) {
    assertNempty(text);
  }
  
  char next() {
    char c = text.charAt(pos);
    pos = (pos+1) % l(text);
    ret c;
  }
  
  bool atStart() {
    ret pos == 0;
  }
}

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