Libraryless. Click here for Pure Java version (4888L/28K).
1 | sclass BestOfN<A> implements Steppable { |
2 | IF1<A, Double> scoreFunction; |
3 | IF0<A> produce; |
4 | long nMax = 1000; |
5 | double stopScore = infinity(); |
6 | |
7 | long attempt; |
8 | new Best<A> best; |
9 | |
10 | *(IF1<A, Double> *scoreFunction, IF0<A> *produce, int *nMax) {} |
11 | *(IF1<A, Double> *scoreFunction, int *nMax) {} |
12 | |
13 | public bool step() { |
14 | if (attempt >= nMax || best.score() >= stopScore) false; |
15 | ++attempt; |
16 | A a = produce!; |
17 | double score = scoreFunction.get(a); |
18 | best.put(a, score); |
19 | true; |
20 | } |
21 | |
22 | run { stepAll(this); } |
23 | |
24 | Scored<A> get() { |
25 | run(); |
26 | ret best.scored(); |
27 | } |
28 | |
29 | double score() { |
30 | ret best.score(); |
31 | } |
32 | |
33 | long attempts() { ret attempt; } |
34 | } |
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: | 173 / 305 |
Version history: | 10 change(s) |
Referenced in: | [show references] |