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

34
LINES

< > BotCompany Repo | #1032511 // BestOfN

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4888L/28K).

sclass BestOfN<A> implements Steppable {
  IF1<A, Double> scoreFunction;
  IF0<A> produce;
  long nMax = 1000;
  double stopScore = infinity();
  
  long attempt;
  new Best<A> best;
  
  *(IF1<A, Double> *scoreFunction, IF0<A> *produce, int *nMax) {}
  *(IF1<A, Double> *scoreFunction, int *nMax) {}
  
  public bool step() {
    if (attempt >= nMax || best.score() >= stopScore) false;
    ++attempt;
    A a = produce!;
    double score = scoreFunction.get(a);
    best.put(a, score);
    true;
  }
  
  run { stepAll(this); }
  
  Scored<A> get() {
    run();
    ret best.scored();
  }
  
  double score() {
    ret best.score();
  }
  
  long attempts() { ret attempt; }
}

Author comment

Began life as a copy of #1032510

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032511
Snippet name: BestOfN
Eternal ID of this version: #1032511/11
Text MD5: c800435eec81f5a9889b5599e0c60a3a
Transpilation MD5: 55bc4da38a77dbdff5a3971010a3ee3c
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-12 11:00:56
Source code size: 711 bytes / 34 lines
Pitched / IR pitched: No / No
Views / Downloads: 172 / 303
Version history: 10 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)